本文整理匯總了TypeScript中@jupyterlab/coreutils.IStateDB類的典型用法代碼示例。如果您正苦於以下問題:TypeScript IStateDB類的具體用法?TypeScript IStateDB怎麽用?TypeScript IStateDB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了IStateDB類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: activateCellTools
/**
* Activate the cell tools extension.
*/
function activateCellTools(app: JupyterLab, tracker: INotebookTracker, editorServices: IEditorServices, state: IStateDB): Promise<ICellTools> {
const id = 'cell-tools';
const celltools = new CellTools({ tracker });
const activeCellTool = new CellTools.ActiveCellTool();
const slideShow = CellTools.createSlideShowSelector();
const nbConvert = CellTools.createNBConvertSelector();
const editorFactory = editorServices.factoryService.newInlineEditor;
const metadataEditor = new CellTools.MetadataEditorTool({ editorFactory });
// Create message hook for triggers to save to the database.
const hook = (sender: any, message: Message): boolean => {
switch (message.type) {
case 'activate-request':
state.save(id, { open: true });
break;
case 'after-hide':
case 'close-request':
state.remove(id);
break;
default:
break;
}
return true;
};
celltools.title.label = 'Cell Tools';
celltools.id = id;
celltools.addItem({ tool: activeCellTool, rank: 1 });
celltools.addItem({ tool: slideShow, rank: 2 });
celltools.addItem({ tool: nbConvert, rank: 3 });
celltools.addItem({ tool: metadataEditor, rank: 4 });
MessageLoop.installMessageHook(celltools, hook);
// Wait until the application has finished restoring before rendering.
Promise.all([state.fetch(id), app.restored]).then(([args]) => {
const open = !!(args && (args as ReadonlyJSONObject)['open'] as boolean);
// After initial restoration, check if the cell tools should render.
if (tracker.size) {
app.shell.addToLeftArea(celltools);
if (open) {
app.shell.activateById(celltools.id);
}
}
// For all subsequent widget changes, check if the cell tools should render.
app.shell.currentChanged.connect((sender, args) => {
// If there are any open notebooks, add cell tools to the side panel if
// it is not already there.
if (tracker.size) {
if (!celltools.isAttached) {
app.shell.addToLeftArea(celltools);
}
return;
}
// If there are no notebooks, close cell tools.
celltools.close();
});
});
return Promise.resolve(celltools);
}
示例2: switch
const hook = (sender: any, message: Message): boolean => {
switch (message.type) {
case 'activate-request':
state.save(id, { open: true });
break;
case 'after-hide':
case 'close-request':
state.remove(id);
break;
default:
break;
}
return true;
};
示例3: switch
const hook = (sender: any, message: Message): boolean => {
switch (message) {
case Widget.Msg.ActivateRequest:
state.save(id, { open: true });
break;
case Widget.Msg.AfterHide:
case Widget.Msg.CloseRequest:
state.remove(id);
break;
default:
break;
}
return true;
};