本文整理汇总了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;
}
//.........这里部分代码省略.........
示例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>;
//.........这里部分代码省略.........
示例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 });
//.........这里部分代码省略.........
示例4:
cleared.then(() => {
router.navigate(url, { silent });
loading.dispose();
});
示例5:
cloned.then(() => {
console.log(`HERE: ${url}`);
router.navigate(url, { silent: true });
});