本文整理汇总了TypeScript中@nteract/core.selectors.content方法的典型用法代码示例。如果您正苦于以下问题:TypeScript selectors.content方法的具体用法?TypeScript selectors.content怎么用?TypeScript selectors.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@nteract/core.selectors
的用法示例。
在下文中一共展示了selectors.content方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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
})
)
)
);
})
示例2: 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
})
);
})
示例3: mergeMap
mergeMap((state: AppState) => {
const content = selectors.content(state, { contentRef });
if (content) {
return of(content);
} else {
return empty();
}
})
示例4: mergeMap
mergeMap((action: actions.PublishGist) => {
const state = state$.value;
const contentRef = action.payload.contentRef;
if (!contentRef) {
return empty();
}
// TODO: Switch GitHub publishing actions to content refs
const content = selectors.content(state, { contentRef });
// NOTE: This could save by having selectors for each model type
// have toDisk() selectors
if (!content || content.type !== "notebook") {
return empty();
}
const filepath = content.filepath;
const notificationSystem = selectors.notificationSystem(state);
const model = content.model;
const notebookString = selectors.notebook.asString(model);
const gistId = selectors.notebook.gistId(model);
// Allow falling back on the GITHUB_TOKEN environment variable
const githubToken = state.app.get("githubToken");
if (githubToken == null) {
return of(
actions.coreError(
new Error("need a github token in order to publish")
)
);
}
if (gistId && typeof gistId !== "string") {
return of(
actions.coreError(new Error("gist id in notebook is not a string"))
);
}
// We are updating, so we require both a gist Id and a github token
// If this doesn't happen to be our originally gisted notebook,
// we should likely fork and publish
//
// TODO: Check to see if the token matches that of the username listed
// in the notebook itself
if (gistId) {
notificationSystem.addNotification({
title: "Updating Gist...",
message: "đđđ",
dismissible: true,
position: "tr",
level: "success"
});
} else {
notificationSystem.addNotification({
title: "Publishing a New Gist...",
message: "â¨đâ¨",
dismissible: true,
position: "tr",
level: "success"
});
}
const filename = filepath ? path.parse(filepath).base : "Untitled.ipynb";
const files: GithubFiles = {
[filename]: { content: notebookString }
};
return publishGist(
{ files, description: filename, public: false },
githubToken,
gistId
).pipe(
mergeMap(xhr => {
const notificationSystem = selectors.notificationSystem(state$.value);
const { id, login } = xhr.response;
// NOTE: One day we need to make this part of our proper store
// instead of hidden side effects
notificationSystem.addNotification({
title: "Gist uploaded",
message: "đ đ˘",
dismissible: true,
position: "tr",
level: "success",
action: {
label: "Open Gist",
callback() {
shell.openExternal(`https://nbviewer.jupyter.org/${id}`);
}
}
});
// TODO: Turn this into one action that does both, even if its
// sometimes a no-op
return of(
actions.overwriteMetadataField({
//.........这里部分代码省略.........