• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript application.IRouter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: StateDB

  activate: (
    app: JupyterFrontEnd,
    paths: JupyterFrontEnd.IPaths,
    router: IRouter,
    resolver: IWindowResolver,
    splash: ISplashScreen | null
  ) => {
    let debouncer: number;
    let resolved = false;

    const { commands, serviceManager } = app;
    const { workspaces } = serviceManager;
    const workspace = resolver.name;
    const transform = new PromiseDelegate<StateDB.DataTransform>();
    const db = new StateDB({
      namespace: app.namespace,
      transform: transform.promise,
      windowName: workspace
    });

    commands.addCommand(CommandIDs.recoverState, {
      execute: async ({ global }) => {
        const immediate = true;
        const silent = true;

        // Clear the state silently so that the state changed signal listener
        // will not be triggered as it causes a save state.
        await db.clear(silent);

        // If the user explictly chooses to recover state, all of local storage
        // should be cleared.
        if (global) {
          try {
            window.localStorage.clear();
            console.log('Cleared local storage');
          } catch (error) {
            console.warn('Clearing local storage failed.', error);

            // To give the user time to see the console warning before redirect,
            // do not set the `immediate` flag.
            return commands.execute(CommandIDs.saveState);
          }
        }

        return commands.execute(CommandIDs.saveState, { immediate });
      }
    });

    // Conflate all outstanding requests to the save state command that happen
    // within the `WORKSPACE_SAVE_DEBOUNCE_INTERVAL` into a single promise.
    let conflated: PromiseDelegate<void> | null = null;

    commands.addCommand(CommandIDs.saveState, {
      label: () => `Save Workspace (${workspace})`,
      execute: ({ immediate }) => {
        const timeout = immediate ? 0 : WORKSPACE_SAVE_DEBOUNCE_INTERVAL;
        const id = workspace;
        const metadata = { id };

        // Only instantiate a new conflated promise if one is not outstanding.
        if (!conflated) {
          conflated = new PromiseDelegate<void>();
        }

        if (debouncer) {
          window.clearTimeout(debouncer);
        }

        debouncer = window.setTimeout(async () => {
          const data = await db.toJSON();

          try {
            await workspaces.save(id, { data, metadata });
            if (conflated) {
              conflated.resolve(undefined);
            }
          } catch (error) {
            if (conflated) {
              conflated.reject(error);
            }
          }
          conflated = null;
        }, timeout);

        return conflated.promise;
      }
    });

    const listener = (sender: any, change: StateDB.Change) => {
      return commands.execute(CommandIDs.saveState);
    };

    commands.addCommand(CommandIDs.loadState, {
      execute: async (args: IRouter.ILocation) => {
        // Since the command can be executed an arbitrary number of times, make
        // sure it is safe to call multiple times.
        if (resolved) {
          return;
        }

//.........这里部分代码省略.........
开发者ID:jupyter,项目名称:jupyterlab,代码行数:101,代码来源:index.ts


示例2: StateDB

  activate: (
    app: JupyterLab,
    router: IRouter,
    resolver: IWindowResolver,
    splash: ISplashScreen
  ) => {
    let debouncer: number;
    let resolved = false;

    const { commands, info, serviceManager } = app;
    const { workspaces } = serviceManager;
    const transform = new PromiseDelegate<StateDB.DataTransform>();
    const state = new StateDB({
      namespace: info.namespace,
      transform: transform.promise,
      windowName: resolver.name
    });

    commands.addCommand(CommandIDs.recoverState, {
      execute: () => {
        const immediate = true;
        const silent = true;

        // Clear the state silently so that the state changed signal listener
        // will not be triggered as it causes a save state.
        return state
          .clear(silent)
          .then(() => commands.execute(CommandIDs.saveState, { immediate }));
      }
    });

    // Conflate all outstanding requests to the save state command that happen
    // within the `WORKSPACE_SAVE_DEBOUNCE_INTERVAL` into a single promise.
    let conflated: PromiseDelegate<void> | null = null;

    commands.addCommand(CommandIDs.saveState, {
      label: () => `Save Workspace (${Private.getWorkspace(router)})`,
      isEnabled: () => !!Private.getWorkspace(router),
      execute: args => {
        const workspace = Private.getWorkspace(router);

        if (!workspace) {
          return;
        }

        const timeout = args.immediate ? 0 : WORKSPACE_SAVE_DEBOUNCE_INTERVAL;
        const id = workspace;
        const metadata = { id };

        // Only instantiate a new conflated promise if one is not outstanding.
        if (!conflated) {
          conflated = new PromiseDelegate<void>();
        }

        if (debouncer) {
          window.clearTimeout(debouncer);
        }

        debouncer = window.setTimeout(() => {
          // Prevent a race condition between the timeout and saving.
          if (!conflated) {
            return;
          }

          state
            .toJSON()
            .then(data => workspaces.save(id, { data, metadata }))
            .then(() => {
              conflated.resolve(undefined);
              conflated = null;
            })
            .catch(reason => {
              conflated.reject(reason);
              conflated = null;
            });
        }, timeout);

        return conflated.promise;
      }
    });

    const listener = (sender: any, change: StateDB.Change) => {
      commands.execute(CommandIDs.saveState);
    };

    commands.addCommand(CommandIDs.loadState, {
      execute: (args: IRouter.ILocation) => {
        // Since the command can be executed an arbitrary number of times, make
        // sure it is safe to call multiple times.
        if (resolved) {
          return;
        }

        const { hash, path, search } = args;
        const workspace = Private.getWorkspace(router);
        const query = URLExt.queryStringToObject(search || '');
        const clone = query['clone'];
        const source = typeof clone === 'string' ? clone : workspace;

        let promise: Promise<any>;
//.........这里部分代码省略.........
开发者ID:dalejung,项目名称:jupyterlab,代码行数:101,代码来源:index.ts


示例3: StateDB

  activate: (app: JupyterLab, router: IRouter) => {
    let debouncer: number;
    let resolved = false;

    const { commands, info, serviceManager } = app;
    const { workspaces } = serviceManager;
    const transform = new PromiseDelegate<StateDB.DataTransform>();
    const state = new StateDB({
      namespace: info.namespace,
      transform: transform.promise
    });

    commands.addCommand(CommandIDs.recoverState, {
      execute: () => {
        const immediate = true;
        const silent = true;

        // Clear the state silently so that the state changed signal listener
        // will not be triggered as it causes a save state.
        return state.clear(silent)
          .then(() => commands.execute(CommandIDs.saveState, { immediate }));
      }
    });

    // Conflate all outstanding requests to the save state command that happen
    // within the `WORKSPACE_SAVE_DEBOUNCE_INTERVAL` into a single promise.
    let conflated: PromiseDelegate<void> | null = null;

    commands.addCommand(CommandIDs.saveState, {
      label: () => `Save Workspace (${Private.getWorkspace(router)})`,
      isEnabled: () => !!Private.getWorkspace(router),
      execute: args => {
        const workspace = Private.getWorkspace(router);

        if (!workspace) {
          return;
        }

        const timeout = args.immediate ? 0 : WORKSPACE_SAVE_DEBOUNCE_INTERVAL;
        const id = workspace;
        const metadata = { id };

        // Only instantiate a new conflated promise if one is not outstanding.
        if (!conflated) {
          conflated = new PromiseDelegate<void>();
        }

        if (debouncer) {
          window.clearTimeout(debouncer);
        }

        debouncer = window.setTimeout(() => {
          state.toJSON()
            .then(data => workspaces.save(id, { data, metadata }))
            .then(() => {
              conflated.resolve(undefined);
              conflated = null;
            })
            .catch(reason => {
              conflated.reject(reason);
              conflated = null;
            });
        }, timeout);

        return conflated.promise;
      }
    });

    const listener = (sender: any, change: StateDB.Change) => {
      commands.execute(CommandIDs.saveState);
    };

    commands.addCommand(CommandIDs.loadState, {
      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 });
//.........这里部分代码省略.........
开发者ID:cfsmile,项目名称:jupyterlab,代码行数:101,代码来源:index.ts


示例4:

 cleared.then(() => {
   router.navigate(url, { silent });
   loading.dispose();
 });
开发者ID:dalejung,项目名称:jupyterlab,代码行数:4,代码来源:index.ts


示例5:

 cloned.then(() => {
   console.log(`HERE: ${url}`);
   router.navigate(url, { silent: true });
 });
开发者ID:SylvainCorlay,项目名称:jupyterlab,代码行数:4,代码来源:index.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript application.JupyterFrontEndPlugin类代码示例发布时间:2022-05-28
下一篇:
TypeScript application.ILayoutRestorer类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap