src/vs/base/common/observableInternal/experimental/reducer.ts

88 LOC · 80 covered · 8 uncovered · 6 ranges · 47 concepts · 2 introducers · 42 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/base/common/observableInternal/observables/derivedImpl.ts · 459 LOCobservables/derivedImpl.…observable.test|title=observables autorunPerKeyedItem per-key setup fires when items derived through observableFromEvent chain updates|occurrence=1 · 0 introduced LOCobservable.test|title=ob…reducer.ts ×3 · 48 introduced LOCreducer.ts ×3derivedImpl.ts ×4 · 14 introduced LOCderivedImpl.ts ×4derivedImpl.ts ×1 · 3 introduced LOCderivedImpl.ts ×1derivedImpl.ts ×1 · 4 introduced LOCderivedImpl.ts ×1observable.test|title=observables topological order|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables tutorial derived + autorun|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables tutorial read during transaction|occurrence=1, observable.test|title=observables autorun rerun on neutral change autorun reruns on indirect neutral observable double change when changes propagate|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables reading derived in transaction unsubscribes unnecessary observables|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables from event basic|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables autorun rerun on neutral change autorun does not rerun on indirect neutral observable double change|occurrence=1 · 0 introduced LOCobservable.test|title=ob…derived.ts ×1 · 46 introduced LOCderived.ts ×1observable.test|title=observables get in transaction between sets|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables bug: Dont reset states|occurrence=1, observable.test|title=observables set dependency in derived|occurrence=1, +1 · 0 introduced LOCobservable.test|title=ob…derivedImpl.ts ×1 · 8 introduced LOCderivedImpl.ts ×1observable.test|title=observables avoid recomputation of deriveds that are no longer read|occurrence=1 · 0 introduced LOCobservable.test|title=ob…autorunImpl.ts ×2 · 2 introduced LOCautorunImpl.ts ×2observable.test|title=observables from event Handle undefined|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables waitForState resolve|occurrence=1 · 0 introduced LOCobservable.test|title=ob…utilsCancellation.ts ×1 · 1 introduced LOCutilsCancellation.ts ×1derivedImpl.ts ×1 · 4 introduced LOCderivedImpl.ts ×1derivedImpl.ts ×3 · 66 introduced LOCderivedImpl.ts ×3autorun.ts ×1 · 3 introduced LOCautorun.ts ×1observable.test|title=observables recomputeInitiallyAndOnChange should work when a dependency sets an observable|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables autorunPerKeyedItem does not fire per-key observable when same item identity is reused|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables autorunPerKeyedItem batches per-key value updates atomically across one items change|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables tutorial get without observers|occurrence=1 · 0 introduced LOCobservable.test|title=ob…autorun.ts ×2 · 47 introduced LOCautorun.ts ×2observable.test|title=observables tutorial observable + autorun|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables autorun rerun on neutral change autorun reruns on neutral observable double change|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables bug: Event.fromObservable always should get events|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables waitForState resolveImmediate|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables set dependency in autorun|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables observableValue|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables bug: fromObservableLight doesnt subscribe|occurrence=1 · 0 introduced LOCobservable.test|title=ob…baseObservable.ts ×1 · 3 introduced LOCbaseObservable.ts ×1observable.test|title=observables prevent invalid usage reading outside of compute function derived|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables tutorial autorun that receives deltas of signals|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observableSignal.ts ×1 · 3 introduced LOCobservableSignal.ts ×1errors.ts ×1 · 4 introduced LOCerrors.ts ×1autorunImpl.ts ×2 · 20 introduced LOCautorunImpl.ts ×2autorunImpl.ts ×1 · 2 introduced LOCautorunImpl.ts ×1observable.test|title=observables dont run autorun after dispose|occurrence=1 · 0 introduced LOCobservable.test|title=ob…utils.ts ×1 · 6 introduced LOCutils.ts ×1observable.test|title=observables prevent invalid usage reading outside of compute function autorun|occurrence=1 · 0 introduced LOCobservable.test|title=ob…observable.test|title=observables from event get without observers|occurrence=1 · 0 introduced LOCobservable.test|title=ob…reducer.ts ×3 · 49 introduced LOCreducer.ts ×3observable.test|title=observables autorun error handling immediate throw|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorun error handling immediate throw|occurrence=1observable.test|title=ob…observable.test|title=observables autorun error handling late throw|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorun error handling late throw|occurrence=1observable.test|title=ob…observable.test|title=observables autorun rerun on neutral change autorun does not rerun on indirect neutral observable double change|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorun rerun on neutral change autorun does not rerun on indirect neutral observable double change|occurrence=1observable.test|title=ob…observable.test|title=observables autorun rerun on neutral change autorun reruns on indirect neutral observable double change when changes propagate|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorun rerun on neutral change autorun reruns on indirect neutral observable double change when changes propagate|occurrence=1observable.test|title=ob…observable.test|title=observables autorun rerun on neutral change autorun reruns on neutral observable double change|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorun rerun on neutral change autorun reruns on neutral observable double change|occurrence=1observable.test|title=ob…observable.test|title=observables autorunPerKeyedItem batches per-key value updates atomically across one items change|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorunPerKeyedItem batches per-key value updates atomically across one items change|occurrence=1observable.test|title=ob…observable.test|title=observables autorunPerKeyedItem does not fire per-key observable when same item identity is reused|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorunPerKeyedItem does not fire per-key observable when same item identity is reused|occurrence=1observable.test|title=ob…observable.test|title=observables autorunPerKeyedItem per-key setup fires when items derived through observableFromEvent chain updates|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorunPerKeyedItem per-key setup fires when items derived through observableFromEvent chain updates|occurrence=1observable.test|title=ob…observable.test|title=observables autorunPerKeyedItem runs setup once per key, fires per-key observable on in-place value change, disposes on removal|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables autorunPerKeyedItem runs setup once per key, fires per-key observable on in-place value change, disposes on removal|occurrence=1observable.test|title=ob…observable.test|title=observables avoid recomputation of deriveds that are no longer read|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables avoid recomputation of deriveds that are no longer read|occurrence=1observable.test|title=ob…observable.test|title=observables bug: Add observable in endUpdate|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables bug: Add observable in endUpdate|occurrence=1observable.test|title=ob…observable.test|title=observables bug: Dont reset states|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables bug: Dont reset states|occurrence=1observable.test|title=ob…observable.test|title=observables bug: Event.fromObservable always should get events|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables bug: Event.fromObservable always should get events|occurrence=1observable.test|title=ob…observable.test|title=observables bug: fromObservableLight doesnt subscribe|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables bug: fromObservableLight doesnt subscribe|occurrence=1observable.test|title=ob…observable.test|title=observables changing observables in endUpdate|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables changing observables in endUpdate|occurrence=1observable.test|title=ob…observable.test|title=observables derivedHandleChanges with reportChanges|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables derivedHandleChanges with reportChanges|occurrence=1observable.test|title=ob…observable.test|title=observables disposableStores derived with delayedStore|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables disposableStores derived with delayedStore|occurrence=1observable.test|title=ob…observable.test|title=observables disposableStores derived with store|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables disposableStores derived with store|occurrence=1observable.test|title=ob…observable.test|title=observables dont run autorun after dispose|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables dont run autorun after dispose|occurrence=1observable.test|title=ob…observable.test|title=observables from event Handle undefined|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables from event Handle undefined|occurrence=1observable.test|title=ob…observable.test|title=observables from event basic|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables from event basic|occurrence=1observable.test|title=ob…observable.test|title=observables from event get without observers|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables from event get without observers|occurrence=1observable.test|title=ob…observable.test|title=observables get in transaction between sets|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables get in transaction between sets|occurrence=1observable.test|title=ob…observable.test|title=observables observableReducer main|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables observableReducer main|occurrence=1observable.test|title=ob…observable.test|title=observables observableValue|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables observableValue|occurrence=1observable.test|title=ob…observable.test|title=observables prevent invalid usage reading outside of compute function autorun|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables prevent invalid usage reading outside of compute function autorun|occurrence=1observable.test|title=ob…observable.test|title=observables prevent invalid usage reading outside of compute function derived|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables prevent invalid usage reading outside of compute function derived|occurrence=1observable.test|title=ob…observable.test|title=observables reading derived in transaction unsubscribes unnecessary observables|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables reading derived in transaction unsubscribes unnecessary observables|occurrence=1observable.test|title=ob…observable.test|title=observables recomputeInitiallyAndOnChange should work when a dependency sets an observable|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables recomputeInitiallyAndOnChange should work when a dependency sets an observable|occurrence=1observable.test|title=ob…observable.test|title=observables self-disposing autorun|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables self-disposing autorun|occurrence=1observable.test|title=ob…observable.test|title=observables set dependency in autorun|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables set dependency in autorun|occurrence=1observable.test|title=ob…observable.test|title=observables set dependency in derived|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables set dependency in derived|occurrence=1observable.test|title=ob…observable.test|title=observables topological order|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables topological order|occurrence=1observable.test|title=ob…observable.test|title=observables tutorial autorun that receives deltas of signals|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables tutorial autorun that receives deltas of signals|occurrence=1observable.test|title=ob…observable.test|title=observables tutorial derived + autorun|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables tutorial derived + autorun|occurrence=1observable.test|title=ob…observable.test|title=observables tutorial get without observers|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables tutorial get without observers|occurrence=1observable.test|title=ob…observable.test|title=observables tutorial observable + autorun|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables tutorial observable + autorun|occurrence=1observable.test|title=ob…observable.test|title=observables tutorial read during transaction|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables tutorial read during transaction|occurrence=1observable.test|title=ob…observable.test|title=observables waitForState derived as lazy|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables waitForState derived as lazy|occurrence=1observable.test|title=ob…observable.test|title=observables waitForState reject|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables waitForState reject|occurrence=1observable.test|title=ob…observable.test|title=observables waitForState resolveImmediate|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables waitForState resolveImmediate|occurrence=1observable.test|title=ob…observable.test|title=observables waitForState resolve|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/observables/observable.test|title=observables waitForState resolve|occurrence=1observable.test|title=ob…Focused file · src/vs/base/common/observableInternal/experimental/reducer.ts · 88 LOCexperimental/reducer.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- reducer.ts ×3
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { EqualityComparer, strictEquals, BugIndicatingError } from '../commonFacade/deps.js';
7 > import { IObservable, IObservableWithChange, ISettableObservable } from '../base.js';
8 > import { subtransaction } from '../transaction.js';
9 > import { IChangeTracker } from '../changeTracker.js';
10 > import { DebugNameData, DebugOwner } from '../debugName.js';
11 > import { DerivedWithSetter, IDerivedReader } from '../observables/derivedImpl.js';
12 > import { DebugLocation } from '../debugLocation.js';
13 >
14 > export interface IReducerOptions<T, TChangeSummary = void, TOutChange = void> {
15 > /**
16 > * Is called to create the initial value of the observable when it becomes observed.
17 > */
18 > initial: T | (() => T);
19 >
20 > /**
21 > * Is called to dispose the observable value when it is no longer observed.
22 > */
23 > disposeFinal?(value: T): void;
24 > changeTracker?: IChangeTracker<TChangeSummary>;
25 > equalityComparer?: EqualityComparer<T>;
26 >
27 > /**
28 > * Applies the changes to the value.
29 > * Use `reader.reportChange` to report change details or to report a change if the same value is returned.
30 > */
31 > update(reader: IDerivedReader<TOutChange>, previousValue: T, changes: TChangeSummary): T;
32 > }
33 >
34 > /**
35 > * Creates an observable value that is based on values and changes from other observables.
36 > * Additionally, a reducer can report how that state changed.
37 > */
38 > export function observableReducer<T, TInChanges, TOutChange = void>(owner: DebugOwner, options: IReducerOptions<T, TInChanges, TOutChange>): SimplifyObservableWithChange<T, TOutChange> {
39 > // eslint-disable-next-line local/code-no-any-casts reducer.ts ×3
40 > return observableReducerSettable<T, TInChanges, TOutChange>(owner, options) as any;
41 > }
43 > /**
44 > * Creates an observable value that is based on values and changes from other observables.
45 > * Additionally, a reducer can report how that state changed.
46 > */
47 > export function observableReducerSettable<T, TInChanges, TOutChange = void>(owner: DebugOwner, options: IReducerOptions<T, TInChanges, TOutChange>): ISettableObservable<T, TOutChange> {
48 > let prevValue: T | undefined = undefined; reducer.ts ×3
49 > let hasValue = false;
50 >
51 > const d = new DerivedWithSetter(
52 > new DebugNameData(owner, undefined, options.update),
53 > (reader: IDerivedReader<TOutChange>, changeSummary) => {
54 > if (!hasValue) {
55 > prevValue = options.initial instanceof Function ? options.initial() : options.initial;
56 > hasValue = true;
57 > }
58 > const newValue = options.update(reader, prevValue!, changeSummary);
59 > prevValue = newValue;
60 > return newValue;
61 > },
62 > options.changeTracker,
63 > () => {
64 > if (hasValue) {
65 > options.disposeFinal?.(prevValue!);
66 > hasValue = false;
67 > }
68 > },
69 > options.equalityComparer ?? strictEquals,
70 > (value, tx, change) => {
71 if (!hasValue) {
72 throw new BugIndicatingError('Can only set when there is a listener! This is to prevent leaks.');
73 }
74 subtransaction(tx, tx => {
75 prevValue = value;
76 d.setValue(value, tx, change);
77 });
78 },
79 > DebugLocation.ofCaller() reducer.ts ×3
80 > );
81 >
82 > return d;
83 > }
85 > /**
86 > * Returns IObservable<T> if TChange is void, otherwise IObservableWithChange<T, TChange>
87 > */
88 > type SimplifyObservableWithChange<T, TChange> = TChange extends void ? IObservable<T> : IObservableWithChange<T, TChange>;