How to use the @jupyterlab/docregistry.Context function in @jupyterlab/docregistry

To help you get started, we’ve selected a few @jupyterlab/docregistry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / docmanager / src / manager.ts View on Github external
// 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();
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / docmanager / src / manager.ts View on Github external
// 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();
github jupyterlab / jupyterlab-data-explorer / tests / test-docregistry / src / context.spec.ts View on Github external
it('should create a new context', () => {
        context = new Context({
          manager,
          factory,
          path: UUID.uuid4() + '.txt'
        });
        expect(context).to.be.an.instanceof(Context);
      });
    });
github jupyterlab / jupyterlab-data-explorer / tests / test-docregistry / src / context.spec.ts View on Github external
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;
        });
github jupyterlab / jupyterlab / tests / test-docregistry / src / context.spec.ts View on Github external
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);
      });
    });
github jupyterlab / jupyterlab / testutils / src / index.ts View on Github external
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;
  }
github jupyterlab / jupyterlab-data-explorer / tests / test-csvviewer / src / widget.spec.ts View on Github external
function createContext(): Context {
  const factory = new TextModelFactory();
  const manager = new ServiceManager({ standby: 'never' });
  const path = UUID.uuid4() + '.csv';
  return new Context({ factory, manager, path });
}
github jupyterlab / jupyterlab / tests / test-docmanager / src / savehandler.spec.ts View on Github external
beforeEach(() => {
    context = new Context({
      manager,
      factory,
      path: UUID.uuid4() + '.txt'
    });
    handler = new SaveHandler({ context });
    return context.initialize(true);
  });
github yuvipanda / simplest-notebook / testutils / src / index.ts View on Github external
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 }
  });
}
github jupyterlab / jupyterlab-data-explorer / jupyterlab / testutils / src / index.ts View on Github external
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 }
  });
}