本文整理汇总了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) {
示例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();
示例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 });