本文整理汇总了TypeScript中@nteract/core.selectors.model方法的典型用法代码示例。如果您正苦于以下问题:TypeScript selectors.model方法的具体用法?TypeScript selectors.model怎么用?TypeScript selectors.model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@nteract/core.selectors
的用法示例。
在下文中一共展示了selectors.model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: onBeforeUnloadOrReload
export function onBeforeUnloadOrReload(
contentRef: ContentRef,
store: DesktopStore,
reloading: boolean
) {
const state = store.getState();
const model = selectors.model(state, { contentRef });
if (!model || model.type !== "notebook") {
// No model on the page, don't block them
return;
}
const closingState = state.desktopNotebook.closingState;
if (closingState === DESKTOP_NOTEBOOK_CLOSING_NOT_STARTED) {
// Dispatch asynchronously since returning ASAP is imperative for canceling close/unload.
// See https://github.com/electron/electron/issues/12668
setTimeout(
() => store.dispatch(closeNotebook({ contentRef, reloading })),
0
);
}
if (closingState !== DESKTOP_NOTEBOOK_CLOSING_READY_TO_CLOSE) {
return false;
}
}
示例2: exportPDF
export function exportPDF(
ownProps: { contentRef: ContentRef },
store: DesktopStore,
basepath: string,
notificationSystem: NotificationSystemRef
): void {
const state = store.getState();
const pdfPath = `${basepath}.pdf`;
const model = selectors.model(state, ownProps);
if (!model || model.type !== "notebook") {
throw new Error(
"Massive strangeness in the desktop app if someone is exporting a non-notebook to PDF"
);
}
const unexpandedCells = selectors.notebook.hiddenCellIds(model);
// TODO: we should not be modifying the document to print PDFs
// and we especially shouldn't be relying on all these actions to
// run through before we print...
// Expand unexpanded cells
unexpandedCells.map((cellId: string) =>
store.dispatch(
actions.toggleOutputExpansion({
id: cellId,
contentRef: ownProps.contentRef
})
)
);
remote.getCurrentWindow().webContents.printToPDF(
{
printBackground: true
},
(error, data) => {
if (error) {
throw error;
}
// Restore the modified cells to their unexpanded state.
unexpandedCells.map((cellId: string) =>
store.dispatch(
actions.toggleOutputExpansion({
id: cellId,
contentRef: ownProps.contentRef
})
)
);
const notificationSystem = state.app.get("notificationSystem");
fs.writeFile(pdfPath, data, _error_fs => {
notificationSystem.addNotification({
title: "PDF exported",
message: `Notebook ${basepath} has been exported as a pdf.`,
dismissible: true,
position: "tr",
level: "success",
action: {
label: "Open PDF",
callback() {
shell.openItem(pdfPath);
}
}
});
});
}
);
}