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


TypeScript IRouter.register方法代码示例

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


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

示例1: StateDB


//.........这里部分代码省略.........

        return promise
          .catch(reason => {
            console.warn(`${CommandIDs.loadState} failed:`, reason);
          })
          .then(() => {
            const immediate = true;

            if (source === clone) {
              // Maintain the query string parameters but remove `clone`.
              delete query['clone'];

              const url = path + URLExt.objectToQueryString(query) + hash;
              const cloned = commands
                .execute(CommandIDs.saveState, { immediate })
                .then(() => router.stop);

              // After the state has been cloned, navigate to the URL.
              cloned.then(() => {
                router.navigate(url, { silent: true });
              });

              return cloned;
            }

            // After the state database has finished loading, save it.
            return commands.execute(CommandIDs.saveState, { immediate });
          });
      }
    });
    // Both the load state and clone state patterns should trigger the load
    // state command if the URL matches one of them, but cloning a workspace
    // outranks loading it because it is an explicit user action.
    router.register({
      command: CommandIDs.loadState,
      pattern: Patterns.cloneState,
      rank: 20 // Set loading rank at a higher priority than the default 100.
    });
    router.register({
      command: CommandIDs.loadState,
      pattern: Patterns.loadState,
      rank: 30 // Set loading rank at a higher priority than the default 100.
    });

    commands.addCommand(CommandIDs.reset, {
      label: 'Reset Application State',
      execute: () => {
        commands
          .execute(CommandIDs.recoverState)
          .then(() => {
            router.reload();
          })
          .catch(() => {
            router.reload();
          });
      }
    });

    commands.addCommand(CommandIDs.resetOnLoad, {
      execute: (args: IRouter.ILocation) => {
        const { hash, path, search } = args;
        const query = URLExt.queryStringToObject(search || '');
        const reset = 'reset' in query;
        const clone = 'clone' in query;

        if (!reset) {
开发者ID:dalejung,项目名称:jupyterlab,代码行数:67,代码来源:index.ts

示例2: StateDB


//.........这里部分代码省略.........
        // Any time the local state database changes, save the workspace.
        if (workspace) {
          state.changed.connect(
            listener,
            state
          );
        }

        const immediate = true;

        if (source === clone) {
          // Maintain the query string parameters but remove `clone`.
          delete query['clone'];

          const url = path + URLExt.objectToQueryString(query) + hash;
          const cloned = commands
            .execute(CommandIDs.saveState, { immediate })
            .then(() => router.stop);

          // After the state has been cloned, navigate to the URL.
          cloned.then(() => {
            console.log(`HERE: ${url}`);
            router.navigate(url, { silent: true });
          });

          return cloned;
        }

        // After the state database has finished loading, save it.
        return commands.execute(CommandIDs.saveState, { immediate });
      }
    });

    router.register({
      command: CommandIDs.loadState,
      pattern: /.?/,
      rank: 20 // Very high priority: 20/100.
    });

    commands.addCommand(CommandIDs.reset, {
      label: 'Reset Application State',
      execute: async () => {
        const global = true;

        try {
          await commands.execute(CommandIDs.recoverState, { global });
        } catch (error) {
          /* Ignore failures and redirect. */
        }
        router.reload();
      }
    });

    commands.addCommand(CommandIDs.resetOnLoad, {
      execute: (args: IRouter.ILocation) => {
        const { hash, path, search } = args;
        const query = URLExt.queryStringToObject(search || '');
        const reset = 'reset' in query;
        const clone = 'clone' in query;

        if (!reset) {
          return;
        }

        const loading = splash.show();
开发者ID:willingc,项目名称:jupyterlab,代码行数:66,代码来源:index.ts

示例3: StateDB


//.........这里部分代码省略.........
      execute: (args: IRouter.ILocation) => {
        const workspace = Private.getWorkspace(router);

        // If there is no workspace, bail.
        if (!workspace) {
          return;
        }

        // Any time the local state database changes, save the workspace.
        state.changed.connect(listener, state);

        // Fetch the workspace and overwrite the state database.
        return workspaces.fetch(workspace).then(session => {
          // If this command is called after a reset, the state database will
          // already be resolved.
          if (!resolved) {
            resolved = true;
            transform.resolve({ type: 'overwrite', contents: session.data });
          }
        }).catch(reason => {
          console.warn(`Fetching workspace (${workspace}) failed.`, reason);

          // If the workspace does not exist, cancel the data transformation and
          // save a workspace with the current user state data.
          if (!resolved) {
            resolved = true;
            transform.resolve({ type: 'cancel', contents: null });
          }

          return commands.execute(CommandIDs.saveState);
        });
      }
    });
    router.register({
      command: CommandIDs.loadState,
      pattern: Patterns.loadState
    });

    commands.addCommand(CommandIDs.reset, {
      label: 'Reset Application State',
      execute: () => {
        commands.execute(CommandIDs.recoverState)
          .then(() => { document.location.reload(); })
          .catch(() => { document.location.reload(); });
      }
    });

    commands.addCommand(CommandIDs.resetOnLoad, {
      execute: (args: IRouter.ILocation) => {
        const { hash, path, search } = args;
        const query = URLExt.queryStringToObject(search || '');
        const reset = 'reset' in query;

        if (!reset) {
          return;
        }

        // If the state database has already been resolved, resetting is
        // impossible without reloading.
        if (resolved) {
          return document.location.reload();
        }

        // Empty the state database.
        resolved = true;
        transform.resolve({ type: 'clear', contents: null });
开发者ID:cfsmile,项目名称:jupyterlab,代码行数:67,代码来源:index.ts


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