How to use the @lumino/disposable.DisposableDelegate function in @lumino/disposable

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 / 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);
    });
  }
github jupyterlab / jupyterlab / packages / apputils-extension / src / palette.ts View on Github external
addItem(options: IPaletteItem): IDisposable {
    let item = this._palette.addItem(options as CommandPalette.IItemOptions);
    return new DisposableDelegate(() => {
      this._palette.removeItem(item);
    });
  }
github jupyterlab / jupyterlab / packages / application / src / router.ts View on Github external
register(options: IRouter.IRegisterOptions): IDisposable {
    const { command, pattern } = options;
    const rank = options.rank ?? 100;
    const rules = this._rules;

    rules.set(pattern, { command, rank });

    return new DisposableDelegate(() => {
      rules.delete(pattern);
    });
  }

@lumino/disposable

Lumino Disposable

BSD-3-Clause
Latest version published 6 months ago

Package Health Score

83 / 100
Full package analysis

Similar packages