当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript selectors.content方法代码示例

本文整理汇总了TypeScript中@nteract/core.selectors.content方法的典型用法代码示例。如果您正苦于以下问题:TypeScript selectors.content方法的具体用法?TypeScript selectors.content怎么用?TypeScript selectors.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@nteract/core.selectors的用法示例。


在下文中一共展示了selectors.content方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: mergeMap

    mergeMap(action => {
      const state = state$.value;
      const contentRef = action.payload.contentRef;

      const content = selectors.content(state, { contentRef });
      if (!content) {
        return of(
          actions.saveFailed({
            contentRef: action.payload.contentRef,
            error: new Error("no notebook loaded to save")
          })
        );
      }
      const model = content.model;

      if (!model || model.type !== "notebook") {
        return of(
          actions.saveFailed({
            contentRef: action.payload.contentRef,
            error: new Error("no notebook loaded to save")
          })
        );
      }

      const filepath = content.filepath;
      const appVersion = selectors.appVersion(state);
      const notebook = stringifyNotebook(
        toJS(
          model.notebook.setIn(["metadata", "nteract", "version"], appVersion)
        )
      );
      return writeFileObservable(filepath, notebook).pipe(
        map(() => {
          if (process.platform !== "darwin") {
            const notificationSystem = selectors.notificationSystem(
              state$.value
            );
            notificationSystem.addNotification({
              autoDismiss: 2,
              level: "success",
              title: "Save successful!"
            });
          }
          return actions.saveFulfilled({
            contentRef: action.payload.contentRef,
            model: {
              last_modified: new Date()
            }
          });
        }),
        catchError((error: Error) =>
          of(
            actions.saveFailed({
              contentRef: action.payload.contentRef,
              error
            })
          )
        )
      );
    })
开发者ID:nteract,项目名称:nteract,代码行数:60,代码来源:saving.ts

示例2: mergeMap

    mergeMap((action: actions.FetchContentFulfilled) => {
      const contentRef = action.payload.contentRef;

      const content = selectors.content(state$.value, { contentRef });

      if (
        !content ||
        content.type !== "notebook" ||
        content.model.type !== "notebook"
      ) {
        // This epic only handles notebook content
        return empty();
      }

      const filepath = content.filepath;
      const notebook = content.model.notebook;

      const { cwd, kernelSpecName } = extractNewKernel(filepath, notebook);

      return of(
        actions.launchKernelByName({
          kernelSpecName,
          cwd,
          kernelRef: action.payload.kernelRef,
          selectNextKernel: true,
          contentRef: action.payload.contentRef
        })
      );
    })
开发者ID:nteract,项目名称:nteract,代码行数:29,代码来源:loading.ts

示例3: mergeMap

 mergeMap((state: AppState) => {
   const content = selectors.content(state, { contentRef });
   if (content) {
     return of(content);
   } else {
     return empty();
   }
 })
开发者ID:nteract,项目名称:nteract,代码行数:8,代码来源:native-window.ts

示例4: mergeMap

    mergeMap((action: actions.PublishGist) => {
      const state = state$.value;

      const contentRef = action.payload.contentRef;
      if (!contentRef) {
        return empty();
      }

      // TODO: Switch GitHub publishing actions to content refs
      const content = selectors.content(state, { contentRef });
      // NOTE: This could save by having selectors for each model type
      //       have toDisk() selectors
      if (!content || content.type !== "notebook") {
        return empty();
      }

      const filepath = content.filepath;
      const notificationSystem = selectors.notificationSystem(state);

      const model = content.model;

      const notebookString = selectors.notebook.asString(model);
      const gistId = selectors.notebook.gistId(model);

      // Allow falling back on the GITHUB_TOKEN environment variable
      const githubToken = state.app.get("githubToken");

      if (githubToken == null) {
        return of(
          actions.coreError(
            new Error("need a github token in order to publish")
          )
        );
      }

      if (gistId && typeof gistId !== "string") {
        return of(
          actions.coreError(new Error("gist id in notebook is not a string"))
        );
      }

      // We are updating, so we require both a gist Id and a github token
      // If this doesn't happen to be our originally gisted notebook,
      // we should likely fork and publish
      //
      // TODO: Check to see if the token matches that of the username listed
      //       in the notebook itself
      if (gistId) {
        notificationSystem.addNotification({
          title: "Updating Gist...",
          message: "💖📓💖",
          dismissible: true,
          position: "tr",
          level: "success"
        });
      } else {
        notificationSystem.addNotification({
          title: "Publishing a New Gist...",
          message: "✨📓✨",
          dismissible: true,
          position: "tr",
          level: "success"
        });
      }

      const filename = filepath ? path.parse(filepath).base : "Untitled.ipynb";
      const files: GithubFiles = {
        [filename]: { content: notebookString }
      };

      return publishGist(
        { files, description: filename, public: false },
        githubToken,
        gistId
      ).pipe(
        mergeMap(xhr => {
          const notificationSystem = selectors.notificationSystem(state$.value);

          const { id, login } = xhr.response;

          // NOTE: One day we need to make this part of our proper store
          //       instead of hidden side effects
          notificationSystem.addNotification({
            title: "Gist uploaded",
            message: "📓 📢",
            dismissible: true,
            position: "tr",
            level: "success",
            action: {
              label: "Open Gist",
              callback() {
                shell.openExternal(`https://nbviewer.jupyter.org/${id}`);
              }
            }
          });

          // TODO: Turn this into one action that does both, even if its
          // sometimes a no-op
          return of(
            actions.overwriteMetadataField({
//.........这里部分代码省略.........
开发者ID:nteract,项目名称:nteract,代码行数:101,代码来源:github-publish.ts


注:本文中的@nteract/core.selectors.content方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。