| 1 |
/*--------------------------------------------------------------------------------------------- |
| 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 } from 'vs/base/common/equals'; |
| 7 |
import { ISettableObservable } from 'vs/base/common/observable'; |
| 8 |
import { ObservableValue } from 'vs/base/common/observableInternal/base'; |
| 9 |
import { IDebugNameData, DebugNameData } from 'vs/base/common/observableInternal/debugName'; |
| 10 |
import { LazyObservableValue } from 'vs/base/common/observableInternal/lazyObservableValue'; |
| 11 |
|
| 12 |
export function observableValueOpts<T, TChange = void>( |
| 13 |
options: IDebugNameData & { |
| 14 |
equalsFn?: EqualityComparer<T>; |
| 15 |
lazy?: boolean; |
| 16 |
}, |
| 17 |
initialValue: T |
| 18 |
): ISettableObservable<T, TChange> { |
| 19 |
if (options.lazy) { |
| 20 |
return new LazyObservableValue( |
| 21 |
new DebugNameData(options.owner, options.debugName, undefined), |
| 22 |
initialValue, |
| 23 |
options.equalsFn ?? strictEquals, |
| 24 |
); |
| 25 |
} |
| 26 |
return new ObservableValue( |
| 27 |
new DebugNameData(options.owner, options.debugName, undefined), |
| 28 |
initialValue, |
| 29 |
options.equalsFn ?? strictEquals, |
| 30 |
); |
| 31 |
} |