How to use @lumino/disposable - 10 common examples

To help you get started, we’ve selected a few @lumino/disposable 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 / mainmenu / src / labmenu.ts View on Github external
// trailing, and duplicate separators.
    if (this._includeSeparators) {
      added.push(this.menu.insertItem(insertIndex++, { type: 'separator' }));
    }
    // Insert the group.
    for (let item of items) {
      added.push(this.menu.insertItem(insertIndex++, item));
    }
    // Insert a separator after the group.
    if (this._includeSeparators) {
      added.push(this.menu.insertItem(insertIndex++, { type: 'separator' }));
    }

    ArrayExt.insert(this._groups, groupIndex, rankGroup);

    return new DisposableDelegate(() => {
      added.forEach(i => this.menu.removeItem(i));
      this._groups.splice(groupIndex, 1);
    });
  }
github jupyterlab / lumino / packages / datastore / src / datastore.ts View on Github external
loc: TableLocation<s>,
    slot: (source: Datastore, args: Table.Change<s>) =&gt; void,
    thisArg?: any
  ): IDisposable {
    // A wrapper change signal connection function.
    const wrapper = (source: Datastore, args: Datastore.IChangedArgs) =&gt; {
      // Ignore changes that don't match the requested record.
      if (!args.change[loc.schema.id]) {
        return;
      }
      // Otherwise, call the slot.
      const tc = args.change[loc.schema.id]! as Table.Change<s>;
      slot.bind(thisArg)(source, tc);
    };
    datastore.changed.connect(wrapper);
    return new DisposableDelegate(() =&gt; {
      datastore.changed.disconnect(wrapper);
    });
  }
</s></s></s>
github jupyterlab / jupyterlab / packages / statusbar / src / statusbar.ts View on Github external
}
    } else if (align === 'right') {
      let insertIndex = this._findInsertIndex(this._rightRankItems, rankItem);
      if (insertIndex === -1) {
        this._rightSide.addWidget(item);
        this._rightRankItems.push(rankItem);
      } else {
        ArrayExt.insert(this._rightRankItems, insertIndex, rankItem);
        this._rightSide.insertWidget(insertIndex, item);
      }
    } else {
      this._middlePanel.addWidget(item);
    }
    this._refreshItem(id); // Initially refresh the status item.

    const disposable = new DisposableDelegate(() => {
      delete this._statusItems[id];
      if (fullStatusItem.activeStateChanged) {
        fullStatusItem.activeStateChanged.disconnect(onActiveStateChanged);
      }
      item.parent = null;
      item.dispose();
    });
    this._disposables.add(disposable);
    return disposable;
  }
github jupyterlab / jupyterlab-latex / src / index.ts View on Github external
function addSynctexCommands(
  app: JupyterFrontEnd,
  editorTracker: IEditorTracker,
  pdfTracker: IPDFJSTracker,
  serverSettings: ServerConnection.ISettings
): DisposableSet {
  const disposables = new DisposableSet();

  const hasPDFWidget = () => !!pdfTracker.currentWidget;
  const hasEditorWidget = () => !!editorTracker.currentWidget;

  // Add the command for the PDF-to-editor mapping.
  disposables.add(
    app.commands.addCommand(CommandIDs.synctexEdit, {
      execute: () => {
        // Get the pdf widget that had its contextMenu activated.
        let widget = pdfTracker.currentWidget;
        if (widget) {
          // Get the page number.
          const pos = widget.content.position;

          // Request the synctex position for the PDF
          return synctexEditRequest(
github jupyterlab / jupyterlab-latex / src / index.ts View on Github external
.then(([settings]) => {
      let disposables = new DisposableSet();
      const onSettingsUpdated = (settings: ISettingRegistry.ISettings) => {
        // Get the new value of the synctex setting.
        const val = settings.get('synctex').composite as boolean | null;
        synctex = val === true || val === false ? val : true;
        // Trash any existing synctex commands
        disposables.dispose();

        // If SyncTeX is enabled, add the commands.
        if (synctex) {
          disposables = addSynctexCommands(
            app,
            editorTracker,
            pdfTracker,
            serverSettings
          );
        }
github jupyterlab / jupyterlab / tests / test-docregistry / src / registry.spec.ts View on Github external
createNew(widget: Widget, context: DocumentRegistry.Context): IDisposable {
    return new DisposableDelegate(() => undefined);
  }
}
github jupyterlab / jupyterlab / packages / docregistry / src / registry.ts View on Github external
addWidgetExtension(
    widgetName: string,
    extension: DocumentRegistry.WidgetExtension
  ): IDisposable {
    widgetName = widgetName.toLowerCase();
    if (!(widgetName in this._extenders)) {
      this._extenders[widgetName] = [];
    }
    let extenders = this._extenders[widgetName];
    let index = ArrayExt.firstIndexOf(extenders, extension);
    if (index !== -1) {
      console.warn(`Duplicate registered extension for ${widgetName}`);
      return new DisposableDelegate(Private.noOp);
    }
    this._extenders[widgetName].push(extension);
    this._changed.emit({
      type: 'widgetExtension',
      name: widgetName,
      change: 'added'
    });
    return new DisposableDelegate(() => {
      ArrayExt.removeFirstOf(this._extenders[widgetName], extension);
      this._changed.emit({
        type: 'widgetExtension',
        name: widgetName,
        change: 'removed'
      });
    });
  }
github jupyterlab / jupyterlab / packages / docregistry / src / registry.ts View on Github external
addFileType(fileType: Partial): IDisposable {
    let value: DocumentRegistry.IFileType = {
      ...DocumentRegistry.fileTypeDefaults,
      ...fileType
    };
    this._fileTypes.push(value);

    this._changed.emit({
      type: 'fileType',
      name: value.name,
      change: 'added'
    });
    return new DisposableDelegate(() =&gt; {
      ArrayExt.removeFirstOf(this._fileTypes, value);
      this._changed.emit({
        type: 'fileType',
        name: fileType.name,
        change: 'removed'
      });
    });
  }
github jupyterlab / jupyterlab / packages / docregistry / src / registry.ts View on Github external
addWidgetFactory(factory: DocumentRegistry.WidgetFactory): IDisposable {
    let name = factory.name.toLowerCase();
    if (!name || name === 'default') {
      throw Error('Invalid factory name');
    }
    if (this._widgetFactories[name]) {
      console.warn(`Duplicate registered factory ${name}`);
      return new DisposableDelegate(Private.noOp);
    }
    this._widgetFactories[name] = factory;
    for (let ft of factory.defaultFor || []) {
      if (factory.fileTypes.indexOf(ft) === -1) {
        continue;
      }
      if (ft === '*') {
        this._defaultWidgetFactory = name;
      } else {
        this._defaultWidgetFactories[ft] = name;
      }
    }
    for (let ft of factory.defaultRendered || []) {
      if (factory.fileTypes.indexOf(ft) === -1) {
        continue;
      }
github jupyterlab / jupyterlab / packages / codemirror / src / editor.ts View on Github external
addKeydownHandler(handler: CodeEditor.KeydownHandler): IDisposable {
    this._keydownHandlers.push(handler);
    return new DisposableDelegate(() => {
      ArrayExt.removeAllWhere(this._keydownHandlers, val => val === handler);
    });
  }

@lumino/disposable

Lumino Disposable

BSD-3-Clause
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis

Similar packages