Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// old context before opening the new context. This will make things much
// more consistent for the users, at the cost of some confusion about what
// models are and why sometimes they cannot open the same file in different
// widgets that have different models.
// Allow options to be passed when adding a sibling.
let adopter = (
widget: IDocumentWidget,
options?: DocumentRegistry.IOpenOptions
) => {
this._widgetManager.adoptWidget(context, widget);
this._opener.open(widget, options);
};
let modelDBFactory =
this.services.contents.getModelDBFactory(path) || undefined;
let context = new Context({
opener: adopter,
manager: this.services,
factory,
path,
kernelPreference,
modelDBFactory,
setBusy: this._setBusy
});
let handler = new SaveHandler({
context,
saveInterval: this.autosaveInterval
});
Private.saveHandlerProperty.set(context, handler);
void context.ready.then(() => {
if (this.autosave) {
handler.start();
// old context before opening the new context. This will make things much
// more consistent for the users, at the cost of some confusion about what
// models are and why sometimes they cannot open the same file in different
// widgets that have different models.
// Allow options to be passed when adding a sibling.
let adopter = (
widget: IDocumentWidget,
options?: DocumentRegistry.IOpenOptions
) => {
this._widgetManager.adoptWidget(context, widget);
this._opener.open(widget, options);
};
let modelDBFactory =
this.services.contents.getModelDBFactory(path) || undefined;
let context = new Context({
opener: adopter,
manager: this.services,
factory,
path,
kernelPreference,
modelDBFactory,
setBusy: this._setBusy
});
let handler = new SaveHandler({
context,
saveInterval: this.autosaveInterval
});
Private.saveHandlerProperty.set(context, handler);
context.ready.then(() => {
if (this.autosave) {
handler.start();
it('should create a new context', () => {
context = new Context({
manager,
factory,
path: UUID.uuid4() + '.txt'
});
expect(context).to.be.an.instanceof(Context);
});
});
it("should emit 'failed' when the save operation fails out", async () => {
context = new Context({
manager,
factory,
path: 'src/readonly-temp.txt'
});
let called = 0;
let checked;
context.saveState.connect((sender, args) => {
if (called > 0) {
expect(sender).to.equal(context);
checked = args;
}
called += 1;
});
it('should add a sibling widget', () => {
let called = false;
const opener = (widget: Widget) => {
called = true;
};
context = new Context({
manager,
factory,
path: UUID.uuid4() + '.txt',
opener
});
context.addSibling(new Widget());
expect(called).to.equal(true);
});
});
export async function initNotebookContext(
options: {
path?: string;
manager?: ServiceManager.IManager;
startKernel?: boolean;
} = {}
): Promise> {
const factory = Private.notebookFactory;
const manager = options.manager || Private.getManager();
const path = options.path || UUID.uuid4() + '.ipynb';
const startKernel =
options.startKernel === undefined ? false : options.startKernel;
await manager.ready;
let context = new Context({
manager,
factory,
path,
kernelPreference: {
shouldStart: startKernel,
canStart: startKernel,
shutdownOnClose: true,
name: manager.specs.default
}
});
await context.initialize(true);
if (startKernel) {
await context.session.initialize();
await context.session.kernel.ready;
}
function createContext(): Context {
const factory = new TextModelFactory();
const manager = new ServiceManager({ standby: 'never' });
const path = UUID.uuid4() + '.csv';
return new Context({ factory, manager, path });
}
beforeEach(() => {
context = new Context({
manager,
factory,
path: UUID.uuid4() + '.txt'
});
handler = new SaveHandler({ context });
return context.initialize(true);
});
export async function createNotebookContext(
path?: string,
manager?: ServiceManager.IManager
): Promise> {
const factory = Private.notebookFactory;
manager = manager || Private.getManager();
path = path || UUID.uuid4() + '.ipynb';
await manager.ready;
return new Context({
manager,
factory,
path,
kernelPreference: { name: manager.specs.default }
});
}
export async function createNotebookContext(
path?: string,
manager?: ServiceManager.IManager
): Promise> {
const factory = Private.notebookFactory;
manager = manager || Private.getManager();
path = path || UUID.uuid4() + '.ipynb';
await manager.ready;
return new Context({
manager,
factory,
path,
kernelPreference: { name: manager.specs.default }
});
}