本文整理汇总了TypeScript中@nteract/core.selectors类的典型用法代码示例。如果您正苦于以下问题:TypeScript selectors类的具体用法?TypeScript selectors怎么用?TypeScript selectors使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了selectors类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: cwdKernelFallback
index => {
if (index === 0) {
const state = store.getState();
const oldKernelRef = selectors.kernelRefByContentRef(state, ownProps);
if (!oldKernelRef) {
console.error("kernel not available for relaunch");
return;
}
const kernel = selectors.kernel(state, { kernelRef: oldKernelRef });
if (!kernel) {
console.error("kernel not available for relaunch");
return;
}
const cwd = filepath
? path.dirname(path.resolve(filepath))
: cwdKernelFallback();
// Create a brand new kernel
const kernelRef = createKernelRef();
store.dispatch(
actions.launchKernelByName({
kernelSpecName: kernel.kernelSpecName,
cwd,
selectNextKernel: true,
kernelRef,
contentRef: ownProps.contentRef
})
);
}
resolve();
}
示例2: mergeMap
mergeMap(action => {
const state = state$.value;
const contentRef = action.payload.contentRef;
const content = selectors.content(state, { contentRef });
if (!content) {
return of(
actions.saveFailed({
contentRef: action.payload.contentRef,
error: new Error("no notebook loaded to save")
})
);
}
const model = content.model;
if (!model || model.type !== "notebook") {
return of(
actions.saveFailed({
contentRef: action.payload.contentRef,
error: new Error("no notebook loaded to save")
})
);
}
const filepath = content.filepath;
const appVersion = selectors.appVersion(state);
const notebook = stringifyNotebook(
toJS(
model.notebook.setIn(["metadata", "nteract", "version"], appVersion)
)
);
return writeFileObservable(filepath, notebook).pipe(
map(() => {
if (process.platform !== "darwin") {
const notificationSystem = selectors.notificationSystem(
state$.value
);
notificationSystem.addNotification({
autoDismiss: 2,
level: "success",
title: "Save successful!"
});
}
return actions.saveFulfilled({
contentRef: action.payload.contentRef,
model: {
last_modified: new Date()
}
});
}),
catchError((error: Error) =>
of(
actions.saveFailed({
contentRef: action.payload.contentRef,
error
})
)
)
);
})
示例3: 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;
}
}
示例4: dispatchNewKernel
export function dispatchNewKernel(
ownProps: { contentRef: ContentRef },
store: DesktopStore,
_evt: Event,
kernelSpec: KernelSpec
) {
const state = store.getState();
const filepath = selectors.filepath(state, ownProps);
const cwd =
filepath !== null
? path.dirname(path.resolve(filepath))
: cwdKernelFallback();
// Create a brand new kernel
const kernelRef = createKernelRef();
store.dispatch(
actions.launchKernel({
kernelSpec,
cwd,
selectNextKernel: true,
kernelRef,
contentRef: ownProps.contentRef
})
);
}
示例5: mergeMap
mergeMap((action: actions.FetchContentFulfilled) => {
const contentRef = action.payload.contentRef;
const content = selectors.content(state$.value, { contentRef });
if (
!content ||
content.type !== "notebook" ||
content.model.type !== "notebook"
) {
// This epic only handles notebook content
return empty();
}
const filepath = content.filepath;
const notebook = content.model.notebook;
const { cwd, kernelSpecName } = extractNewKernel(filepath, notebook);
return of(
actions.launchKernelByName({
kernelSpecName,
cwd,
kernelRef: action.payload.kernelRef,
selectNextKernel: true,
contentRef: action.payload.contentRef
})
);
})
示例6: storeToPDF
export function storeToPDF(
ownProps: { contentRef: ContentRef },
store: DesktopStore
) {
const state = store.getState();
const notebookName = selectors.filepath(state, ownProps);
const notificationSystem = state.app.get("notificationSystem");
if (notebookName === null) {
notificationSystem.addNotification({
title: "File has not been saved!",
message: `Click the button below to save the notebook so that it can be
exported as a PDF.`,
dismissible: true,
position: "tr",
level: "warning",
action: {
label: "Save As",
callback() {
triggerSaveAsPDF(ownProps, store);
}
}
});
} else {
const basename = path.basename(notebookName, ".ipynb");
const basepath = path.join(path.dirname(notebookName), basename);
exportPDF(ownProps, store, basepath, notificationSystem);
}
}
示例7: mergeMap
mergeMap((state: AppState) => {
const content = selectors.content(state, { contentRef });
if (content) {
return of(content);
} else {
return empty();
}
})
示例8:
(state: AppState, kernelRef: KernelRef) => {
const kernel = selectors.kernel(state, { kernelRef });
if (!kernel) {
return "not connected";
} else {
return kernel.status;
}
}
示例9: dispatchKillKernel
export function dispatchKillKernel(
ownProps: { contentRef: ContentRef },
store: DesktopStore
) {
const state = store.getState();
const kernelRef = selectors.kernelRefByContentRef(state, ownProps);
if (!kernelRef) {
store.dispatch(actions.coreError(new Error("kernel not set")));
return;
}
store.dispatch(actions.killKernel({ restarting: false, kernelRef }));
}
示例10: dispatchSave
export function dispatchSave(
ownProps: { contentRef: ContentRef },
store: DesktopStore
) {
const state = store.getState();
const filepath = selectors.filepath(state, ownProps);
if (filepath === null || filepath === "") {
triggerSaveAs(ownProps, store);
} else {
store.dispatch(actions.save(ownProps));
}
}