How to use @lumino/coreutils - 10 common examples

To help you get started, we’ve selected a few @lumino/coreutils 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-services / src / kernel / comm.spec.ts View on Github external
it('should get the comm info', async () => {
        const commPromise = new PromiseDelegate();
        const hook = (comm: Kernel.IComm, msg: KernelMessage.ICommOpenMsg) => {
          commPromise.resolve(comm);
        };
        kernel.registerCommTarget('test', hook);

        // Request the comm creation.
        await kernel.requestExecute({ code: SEND }, true).done;

        // Get the comm.
        const comm = await commPromise.promise;

        // Ask the kernel for the list of current comms.
        const msg = await kernel.requestCommInfo({});

        if (msg.content.status !== 'ok') {
          throw new Error('Message error');
github jupyterlab / jupyterlab / tests / test-services / src / utils.ts View on Github external
sock.on('message', (msg: any) => {
      if (msg instanceof Buffer) {
        msg = new Uint8Array(msg).buffer;
      }
      const data = deserialize(msg);
      if (data.header.msg_type === 'kernel_info_request') {
        // First send status busy message.
        this.parentHeader = data.header;
        this.sendStatus(UUID.uuid4(), 'busy');

        // Then send the kernel_info_reply message.
        this.sendKernelInfoReply(UUID.uuid4(), EXAMPLE_KERNEL_INFO);

        // Then send status idle message.
        this.sendStatus(UUID.uuid4(), 'idle');
        this.parentHeader = undefined;
      } else {
        const onMessage = this._onMessage;
        if (onMessage) {
          onMessage(data);
        }
      }
    });
  }
github jupyterlab / jupyterlab / tests / test-console / src / foreign.spec.ts View on Github external
before(async function() {
      // tslint:disable-next-line:no-invalid-this
      this.timeout(60000);

      const path = UUID.uuid4();
      [local, foreign, session] = await Promise.all([
        Session.startNew({ path }),
        Session.startNew({ path }),
        createClientSession({ path })
      ]);

      // check path prop
      expect(local.path).to.equal(path);

      await (session as ClientSession).initialize();
      await session.kernel.ready;
    });
github jupyterlab / jupyterlab / packages / application / src / router.ts View on Github external
const { commands, current, stop } = this;
    const { request } = current;
    const routed = this._routed;
    const rules = this._rules;
    const matches: Private.Rule[] = [];

    // Collect all rules that match the URL.
    rules.forEach((rule, pattern) => {
      if (request?.match(pattern)) {
        matches.push(rule);
      }
    });

    // Order the matching rules by rank and enqueue them.
    const queue = matches.sort((a, b) => b.rank - a.rank);
    const done = new PromiseDelegate();

    // Process each enqueued command sequentially and short-circuit if a promise
    // resolves with the `stop` token.
    const next = async () => {
      if (!queue.length) {
        routed.emit(current);
        done.resolve(undefined);
        return;
      }

      const { command } = queue.pop()!;

      try {
        const request = this.current.request;
        const result = await commands.execute(command, current);
        if (result === stop) {
github jupyterlab / jupyterlab / packages / completer / src / model.ts View on Github external
set original(newValue: Completer.ITextState | null) {
    let unchanged =
      this._original === newValue ||
      (this._original &&
        newValue &&
        JSONExt.deepEqual(newValue, this._original));
    if (unchanged) {
      return;
    }

    this._reset();

    // Set both the current and original to the same value when original is set.
    this._current = this._original = newValue;

    this._stateChanged.emit(undefined);
  }
github jupyterlab / jupyterlab / packages / inspector / src / tokens.ts View on Github external
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Token } from '@lumino/coreutils';

import { ISignal } from '@lumino/signaling';

import { Widget } from '@lumino/widgets';

/* tslint:disable */
/**
 * The inspector panel token.
 */
export const IInspector = new Token(
  '@jupyterlab/inspector:IInspector'
);
/* tslint:enable */

/**
 * An interface for an inspector.
 */
export interface IInspector {
  /**
   * The source of events the inspector listens for.
   */
  source: IInspector.IInspectable | null;
}

/**
 * A namespace for inspector interfaces.
github jupyterlab / jupyterlab / packages / notebook / src / tokens.ts View on Github external
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { IWidgetTracker } from '@jupyterlab/apputils';
import { Cell } from '@jupyterlab/cells';
import { Token } from '@lumino/coreutils';
import { ISignal } from '@lumino/signaling';
import { Widget } from '@lumino/widgets';
import { NotebookPanel } from './panel';
import { NotebookTools } from './notebooktools';

/* tslint:disable */
/**
 * The notebook tools token.
 */
export const INotebookTools = new Token(
  '@jupyterlab/notebook:INotebookTools'
);
/* tslint:enable */

/**
 * The interface for notebook metadata tools.
 */
export interface INotebookTools extends Widget {
  activeNotebookPanel: NotebookPanel | null;
  activeCell: Cell | null;
  selectedCells: Cell[];
  addItem(options: NotebookTools.IAddOptions): void;
}

/**
 * The namespace for NotebookTools class statics.
github jupyterlab / jupyterlab / packages / coreutils / src / tokens.ts View on Github external
Token
} from '@lumino/coreutils';

import { IDisposable } from '@lumino/disposable';

import { ISignal } from '@lumino/signaling';

import { ISchemaValidator } from './settingregistry';

import { IDataConnector } from './interfaces';

/* tslint:disable */
/**
 * The setting registry token.
 */
export const ISettingRegistry = new Token(
  '@jupyterlab/coreutils:ISettingRegistry'
);
/* tslint:enable */

/**
 * The settings registry interface.
 */
export interface ISettingRegistry {
  /**
   * The data connector used by the setting registry.
   */
  readonly connector: IDataConnector;

  /**
   * The schema of the setting registry.
   */
github jupyterlab / jupyterlab / packages / application / src / mimerenderers.ts View on Github external
import { AttachedProperty } from '@lumino/properties';

import { JupyterFrontEnd, JupyterFrontEndPlugin } from './index';

import { ILayoutRestorer } from './layoutrestorer';

/**
 * A class that tracks mime documents.
 */
export interface IMimeDocumentTracker extends IWidgetTracker {}

/* tslint:disable */
/**
 * The mime document tracker token.
 */
export const IMimeDocumentTracker = new Token(
  '@jupyterlab/application:IMimeDocumentTracker'
);
/* tslint:enable */

/**
 * Create rendermime plugins for rendermime extension modules.
 */
export function createRendermimePlugins(
  extensions: IRenderMime.IExtensionModule[]
): JupyterFrontEndPlugin[] {
  const plugins: JupyterFrontEndPlugin[] = [];

  const namespace = 'application-mimedocuments';
  const tracker = new WidgetTracker({ namespace });

  extensions.forEach(mod => {
github jupyterlab / jupyterlab / packages / settingeditor / src / tokens.ts View on Github external
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { IWidgetTracker, MainAreaWidget } from '@jupyterlab/apputils';

import { Token } from '@lumino/coreutils';

import { SettingEditor } from './settingeditor';

/* tslint:disable */
/**
 * The setting editor tracker token.
 */
export const ISettingEditorTracker = new Token(
  '@jupyterlab/settingeditor:ISettingEditorTracker'
);
/* tslint:enable */

/**
 * A class that tracks the setting editor.
 */
export interface ISettingEditorTracker
  extends IWidgetTracker> {}