• Runs the given run function immediately, and whenever an update scope ends and an observable tracked as a dependency of the autorun has changed.

    Note that the run function of the autorun is called within an invocation context where the current accessor is set to track the autorun dependencies, so that any observables accessed with get() will automatically be tracked. Occasionally, it might be useful to disable such automatic tracking and track the dependencies manually with get(accessor). This can be done using the Observable.noAutoTracking function, e.g.

    this.toDispose.push(Autorun.create(() => Observable.noAutoTracking(accessor => {
    const value1 = this.observable1.get(accessor); // the autorun will depend on this observable...
    const value2 = this.observable2.get(); // ...but not on this observable
    })));

    In particular, this pattern might be useful when copying existing autorun code from VS Code, where observables can only be tracked manually with read(reader), which corresponds to get(accessor) in Theia; calls to get() never cause an observable to be tracked. This directly corresponds to disabling automatic tracking in Theia with Observable.noAutoTracking.

    Type Parameters

    • TChangeSummary = void

    Parameters

    Returns Disposable