Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: derivedConstOnceDefined #221959

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/base/common/observableInternal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,6 @@ export function latestChangedValue<T extends IObservable<any>[]>(owner: DebugOwn
* However, if the value is not undefined, it is cached and will not be recomputed anymore.
* In that case, the derived will unsubscribe from its dependencies.
*/
export function getIfDefined<T>(owner: DebugOwner, fn: (reader: IReader) => T): IObservable<T | undefined> {
export function derivedConstOnceDefined<T>(owner: DebugOwner, fn: (reader: IReader) => T | undefined): IObservable<T | undefined> {
return derivedObservableWithCache<T | undefined>(owner, (reader, lastValue) => lastValue ?? fn(reader));
}
14 changes: 7 additions & 7 deletions src/vs/editor/browser/widget/diffEditor/diffEditorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { IObservable, ISettableObservable, derived, observableFromEvent, observableValue } from 'vs/base/common/observable';
import { getIfDefined } from 'vs/base/common/observableInternal/utils';
import { derivedConstOnceDefined } from 'vs/base/common/observableInternal/utils';
import { Constants } from 'vs/base/common/uint';
import { DiffEditorViewModel, DiffState } from 'vs/editor/browser/widget/diffEditor/diffEditorViewModel';
import { diffEditorDefaultOptions } from 'vs/editor/common/config/diffEditor';
Expand Down Expand Up @@ -93,12 +93,12 @@ export class DiffEditorOptions {
}

private readonly shouldRenderInlineViewInSmartMode = this._model
.map(this, model => getIfDefined(this, reader => {
const diffs = model?.diff.read(reader);
return diffs ? isSimpleDiff(diffs) : undefined;
}))
.flatten()
.map(this, v => !!v);
.map(this, model =>
derivedConstOnceDefined(this, reader => {
const diffs = model?.diff.read(reader);
return diffs ? isSimpleDiff(diffs) : undefined;
}).map(this, v => !!v)
).flatten();
}

function isSimpleDiff(diff: DiffState): boolean {
Expand Down
Loading