How to use the @lumino/algorithm.ArrayExt.firstIndexOf function in @lumino/algorithm

To help you get started, we’ve selected a few @lumino/algorithm 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 / mainmenu.ts View on Github external
addMenu(menu: Menu, options: IMainMenu.IAddOptions = {}): void {
    if (ArrayExt.firstIndexOf(this.menus, menu) > -1) {
      return;
    }

    let rank = 'rank' in options ? options.rank : 100;
    let rankItem = { menu, rank };
    let index = ArrayExt.upperBound(this._items, rankItem, Private.itemCmp);

    // Upon disposal, remove the menu and its rank reference.
    menu.disposed.connect(this._onMenuDisposed, this);

    ArrayExt.insert(this._items, index, rankItem);
    /**
     * Create a new menu.
     */
    this.insertMenu(index, menu);
  }
github jupyterlab / jupyterlab / tests / test-mainmenu / src / mainmenu.spec.ts View on Github external
it('should take a rank as an option', () => {
        const menu1 = new Menu({ commands });
        const menu2 = new Menu({ commands });
        mainMenu.addMenu(menu1, { rank: 300 });
        mainMenu.addMenu(menu2, { rank: 200 });
        expect(ArrayExt.firstIndexOf(mainMenu.menus, menu1)).to.equal(6);
        expect(ArrayExt.firstIndexOf(mainMenu.menus, menu2)).to.equal(5);
      });
    });
github jupyterlab / jupyterlab / tests / test-notebook / src / model.spec.ts View on Github external
it('should be reset when loading from disk', () => {
        const model = new NotebookModel();
        const cell = model.contentFactory.createCodeCell({});
        model.cells.push(cell);
        model.fromJSON(NBTestUtils.DEFAULT_CONTENT);
        expect(ArrayExt.firstIndexOf(toArray(model.cells), cell)).to.equal(-1);
        expect(model.cells.length).to.equal(6);
      });
github jupyterlab / jupyterlab / tests / test-mainmenu / src / mainmenu.spec.ts View on Github external
it('should take a rank as an option', () => {
        const menu1 = new Menu({ commands });
        const menu2 = new Menu({ commands });
        mainMenu.addMenu(menu1, { rank: 300 });
        mainMenu.addMenu(menu2, { rank: 200 });
        expect(ArrayExt.firstIndexOf(mainMenu.menus, menu1)).to.equal(6);
        expect(ArrayExt.firstIndexOf(mainMenu.menus, menu2)).to.equal(5);
      });
    });
github jupyterlab / jupyterlab / tests / test-mainmenu / src / mainmenu.spec.ts View on Github external
it('should be the second menu', () => {
        expect(
          ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.editMenu.menu)
        ).to.equal(1);
      });
    });
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'