Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WidgetTracker<T>

A class that keeps track of widget instances on an Application shell.

Type parameters

  • T: Widget = Widget

    The type of widget being tracked. Defaults to Widget.

    Notes

    The API surface area of this concrete implementation is substantially larger than the widget tracker interface it implements. The interface is intended for export by JupyterLab plugins that create widgets and have clients who may wish to keep track of newly created widgets. This class, however, can be used internally by plugins to restore state as well.

Hierarchy

Implements

Index

Constructors

constructor

  • Create a new widget tracker.

    Type parameters

    • T: Widget<T> = Widget

    Parameters

    • options: IOptions

      The instantiation options for a widget tracker.

    Returns WidgetTracker<T>

Properties

Private _currentChanged

_currentChanged: any

Private _focusTracker

_focusTracker: any

Private _isDisposed

_isDisposed: any

Private _pool

_pool: any

Private _widgetAdded

_widgetAdded: any

Private _widgetUpdated

_widgetUpdated: any

Readonly namespace

namespace: string

A namespace for all tracked widgets, (e.g., notebook).

Accessors

currentChanged

  • get currentChanged(): ISignal<this, T>
  • A signal emitted when the current widget changes.

    Returns ISignal<this, T>

currentWidget

  • get currentWidget(): T
  • The current widget is the most recently focused or added widget.

    Notes

    It is the most recently focused widget, or the most recently added widget if no widget has taken focus.

    Returns T

isDisposed

  • get isDisposed(): boolean
  • Test whether the tracker is disposed.

    Returns boolean

restored

  • get restored(): Promise<void>
  • A promise resolved when the tracker has been restored.

    Returns Promise<void>

size

  • get size(): number
  • The number of widgets held by the tracker.

    Returns number

widgetAdded

  • get widgetAdded(): ISignal<this, T>
  • A signal emitted when a widget is added.

    Notes

    This signal will only fire when a widget is added to the tracker. It will not fire if a widget is injected into the tracker.

    Returns ISignal<this, T>

widgetUpdated

  • get widgetUpdated(): ISignal<this, T>
  • A signal emitted when a widget is updated.

    Returns ISignal<this, T>

Methods

add

  • add(widget: T): Promise<void>
  • Add a new widget to the tracker.

    Parameters

    • widget: T

      The widget being added.

      Notes

      The widget passed into the tracker is added synchronously; its existence in the tracker can be checked with the has() method. The promise this method returns resolves after the widget has been added and saved to an underlying restoration connector, if one is available.

      The newly added widget becomes the current widget unless the focus tracker already had a focused widget.

    Returns Promise<void>

dispose

  • dispose(): void
  • Dispose of the resources held by the tracker.

    Returns void

filter

  • filter(fn: (widget: T) => boolean): T[]
  • Filter the widgets in the tracker based on a predicate.

    Parameters

    • fn: (widget: T) => boolean

      The function by which to filter.

        • (widget: T): boolean
        • Parameters

          • widget: T

          Returns boolean

    Returns T[]

find

  • find(fn: (widget: T) => boolean): T
  • Find the first widget in the tracker that satisfies a filter function.

    Parameters

    • fn: (widget: T) => boolean
        • (widget: T): boolean
        • Parameters

          • widget: T

          Returns boolean

    Returns T

forEach

  • forEach(fn: (widget: T) => void): void
  • Iterate through each widget in the tracker.

    Parameters

    • fn: (widget: T) => void

      The function to call on each widget.

        • (widget: T): void
        • Parameters

          • widget: T

          Returns void

    Returns void

has

  • has(widget: Widget): boolean
  • Check if this tracker has the specified widget.

    Parameters

    • widget: Widget

      The widget whose existence is being checked.

    Returns boolean

inject

  • inject(widget: T): Promise<void>
  • Inject a foreign widget into the widget tracker.

    Parameters

    • widget: T

      The widget to inject into the tracker.

      Notes

      Injected widgets will not have their state saved by the tracker.

      The primary use case for widget injection is for a plugin that offers a sub-class of an extant plugin to have its instances share the same commands as the parent plugin (since most relevant commands will use the currentWidget of the parent plugin's widget tracker). In this situation, the sub-class plugin may well have its own widget tracker for layout and state restoration in addition to injecting its widgets into the parent plugin's widget tracker.

    Returns Promise<void>

Protected onCurrentChanged

  • onCurrentChanged(value: T): void
  • Handle the current change event.

    Notes

    The default implementation is a no-op.

    Parameters

    • value: T

    Returns void

restore

  • restore(options: IOptions<T>): Promise<any>
  • Restore the widgets in this tracker's namespace.

    Parameters

    • options: IOptions<T>

      The configuration options that describe restoration.

    Returns Promise<any>

    A promise that resolves when restoration has completed.

    Notes

    This function should not typically be invoked by client code. Its primary use case is to be invoked by a restorer.

save

  • save(widget: T): Promise<void>
  • Save the restore data for a given widget.

    Parameters

    • widget: T

      The widget being saved.

    Returns Promise<void>

Generated using TypeDoc