How to use the @jupyterlab/application.LayoutRestorer function in @jupyterlab/application

To help you get started, we’ve selected a few @jupyterlab/application 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 / tests / test-application / src / layoutrestorer.spec.ts View on Github external
it('should save data', async () => {
        const ready = new PromiseDelegate();
        const restorer = new LayoutRestorer({
          connector: new StateDB(),
          first: ready.promise,
          registry: new CommandRegistry()
        });
        const currentWidget = new Widget();
        // The `fresh` attribute is only here to check against the return value.
        const dehydrated: ILabShell.ILayout = {
          fresh: false,
          mainArea: { currentWidget: null, dock: null, mode: null },
          leftArea: {
            currentWidget,
            collapsed: true,
            widgets: [currentWidget]
          },
          rightArea: { collapsed: true, currentWidget: null, widgets: null }
        };
github jupyterlab / jupyterlab / tests / test-application / src / layoutrestorer.spec.ts View on Github external
it('should construct a new layout restorer', () => {
        const restorer = new LayoutRestorer({
          connector: new StateDB(),
          first: Promise.resolve(void 0),
          registry: new CommandRegistry()
        });
        expect(restorer).to.be.an.instanceof(LayoutRestorer);
      });
    });
github jupyterlab / jupyterlab / tests / test-application / src / layoutrestorer.spec.ts View on Github external
it('should be a promise available right away', () => {
        const restorer = new LayoutRestorer({
          connector: new StateDB(),
          first: Promise.resolve(void 0),
          registry: new CommandRegistry()
        });
        expect(restorer.restored).to.be.an.instanceof(Promise);
      });
github jupyterlab / jupyterlab-data-explorer / tests / test-application / src / layoutrestorer.spec.ts View on Github external
it('should resolve when restorer is done', async () => {
        const ready = new PromiseDelegate();
        const restorer = new LayoutRestorer({
          first: ready.promise,
          registry: new CommandRegistry(),
          state: new StateDB()
        });
        let promise = restorer.restored;
        ready.resolve(void 0);
        await promise;
      });
    });
github jupyterlab / jupyterlab / tests / test-application / src / layoutrestorer.spec.ts View on Github external
it('should restore the widgets in a tracker', async () => {
        const tracker = new WidgetTracker({ namespace: 'foo-widget' });
        const registry = new CommandRegistry();
        const state = new StateDB();
        const ready = new PromiseDelegate();
        const restorer = new LayoutRestorer({
          connector: state,
          first: ready.promise,
          registry
        });
        let called = false;
        const key = `${tracker.namespace}:${tracker.namespace}`;

        registry.addCommand(tracker.namespace, {
          execute: () => {
            called = true;
          }
        });
        await state.save(key, { data: null });
        ready.resolve(undefined);
        await restorer.restore(tracker, {
          name: () => tracker.namespace,
github jupyterlab / jupyterlab-data-explorer / tests / test-application / src / layoutrestorer.spec.ts View on Github external
it('should add a widget to be tracked by the restorer', async () => {
        const ready = new PromiseDelegate();
        const restorer = new LayoutRestorer({
          first: ready.promise,
          registry: new CommandRegistry(),
          state: new StateDB()
        });
        const currentWidget = new Widget();
        const mode: DockPanel.Mode = 'single-document';
        const dehydrated: ILabShell.ILayout = {
          mainArea: { currentWidget, dock: null, mode },
          leftArea: { collapsed: true, currentWidget: null, widgets: null },
          rightArea: { collapsed: true, currentWidget: null, widgets: null }
        };
        restorer.add(currentWidget, 'test-one');
        ready.resolve(void 0);
        await restorer.restored;
        await restorer.save(dehydrated);
        const layout = await restorer.fetch();
github jupyterlab / jupyterlab / tests / test-application / src / layoutrestorer.spec.ts View on Github external
it('should always return a value', async () => {
        const restorer = new LayoutRestorer({
          connector: new StateDB(),
          first: Promise.resolve(void 0),
          registry: new CommandRegistry()
        });
        const layout = await restorer.fetch();
        expect(layout).to.not.equal(null);
      });
github jupyterlab / jupyterlab-data-explorer / tests / test-application / src / layoutrestorer.spec.ts View on Github external
it('should restore the widgets in a tracker', async () => {
        const tracker = new InstanceTracker({
          namespace: 'foo-widget'
        });
        const registry = new CommandRegistry();
        const state = new StateDB();
        const ready = new PromiseDelegate();
        const restorer = new LayoutRestorer({
          first: ready.promise,
          registry,
          state
        });
        let called = false;
        const key = `${tracker.namespace}:${tracker.namespace}`;

        registry.addCommand(tracker.namespace, {
          execute: () => {
            called = true;
          }
        });
        await state.save(key, { data: null });
        ready.resolve(undefined);
        await restorer.restore(tracker, {
          args: () => null,
github jupyterlab / jupyterlab / packages / application-extension / src / index.tsx View on Github external
activate: (app: JupyterLab, state: IStateDB) => {
    const first = app.started;
    const registry = app.commands;
    const restorer = new LayoutRestorer({ first, registry, state });

    restorer.fetch().then(saved => {
      app.shell.restoreLayout(saved);
      app.shell.layoutModified.connect(() => {
        restorer.save(app.shell.saveLayout());
      });
    });

    return restorer;
  },
  autoStart: true,
github jupyterlab / jupyterlab / packages / application-extension / src / index.ts View on Github external
activate: (app: JupyterLab, state: IStateDB) => {
    const first = app.started;
    const registry = app.commands;
    const restorer = new LayoutRestorer({ first, registry, state });

    restorer.fetch().then(saved => {
      app.shell.restoreLayout(saved);
      app.shell.layoutModified.connect(() => {
        restorer.save(app.shell.saveLayout());
      });
    });

    return restorer;
  },
  autoStart: true,