Skip to content

Commit 7e35193

Browse files
authored
Don't use IObservableValue (microsoft#167072)
don't use observable value
1 parent 765c46f commit 7e35193

File tree

15 files changed

+28
-74
lines changed

15 files changed

+28
-74
lines changed

src/vs/base/common/observableValue.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Emitter, Event } from 'vs/base/common/event';
7-
import { Disposable } from 'vs/base/common/lifecycle';
6+
import { Event } from 'vs/base/common/event';
87
//@ts-ignore
98
import type { IObservable } from 'vs/base/common/observable';
109

@@ -16,34 +15,3 @@ export interface IObservableValue<T> {
1615
readonly value: T;
1716
}
1817

19-
/**
20-
* @deprecated Use {@link IObservable} instead.
21-
*/
22-
export const staticObservableValue = <T>(value: T): IObservableValue<T> => ({
23-
onDidChange: Event.None,
24-
value,
25-
});
26-
27-
/**
28-
* @deprecated Use {@link IObservable} instead.
29-
*/
30-
export class MutableObservableValue<T> extends Disposable implements IObservableValue<T> {
31-
private readonly changeEmitter = this._register(new Emitter<T>());
32-
33-
public readonly onDidChange = this.changeEmitter.event;
34-
35-
public get value() {
36-
return this._value;
37-
}
38-
39-
public set value(v: T) {
40-
if (v !== this._value) {
41-
this._value = v;
42-
this.changeEmitter.fire(v);
43-
}
44-
}
45-
46-
constructor(private _value: T) {
47-
super();
48-
}
49-
}

src/vs/editor/standalone/browser/standaloneServices.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ import { MarkerService } from 'vs/platform/markers/common/markerService';
8585
import { IOpenerService } from 'vs/platform/opener/common/opener';
8686
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
8787
import { IStorageService, InMemoryStorageService } from 'vs/platform/storage/common/storage';
88-
import { staticObservableValue } from 'vs/base/common/observableValue';
8988

9089
import 'vs/editor/common/services/languageFeaturesService';
9190
import { DefaultConfigurationModel } from 'vs/platform/configuration/common/configurations';
@@ -690,7 +689,7 @@ class StandaloneResourcePropertiesService implements ITextResourcePropertiesServ
690689
class StandaloneTelemetryService implements ITelemetryService {
691690
declare readonly _serviceBrand: undefined;
692691

693-
public telemetryLevel = staticObservableValue(TelemetryLevel.NONE);
692+
public telemetryLevel = TelemetryLevel.NONE;
694693
public sendErrorTelemetry = false;
695694

696695
public setEnabled(value: boolean): void {

src/vs/platform/telemetry/common/telemetry.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
77
import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings';
8-
import { IObservableValue } from 'vs/base/common/observableValue';
98

109
export const ITelemetryService = createDecorator<ITelemetryService>('telemetryService');
1110

@@ -53,7 +52,7 @@ export interface ITelemetryService {
5352

5453
setExperimentProperty(name: string, value: string): void;
5554

56-
readonly telemetryLevel: IObservableValue<TelemetryLevel>;
55+
readonly telemetryLevel: TelemetryLevel;
5756
}
5857

5958
export interface ITelemetryEndpoint {

src/vs/platform/telemetry/common/telemetryService.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { DisposableStore } from 'vs/base/common/lifecycle';
77
import { mixin } from 'vs/base/common/objects';
8-
import { MutableObservableValue } from 'vs/base/common/observableValue';
98
import { isWeb } from 'vs/base/common/platform';
109
import { escapeRegExpCharacters } from 'vs/base/common/strings';
1110
import { localize } from 'vs/nls';
@@ -36,9 +35,9 @@ export class TelemetryService implements ITelemetryService {
3635
private _commonProperties: Promise<{ [name: string]: any }>;
3736
private _experimentProperties: { [name: string]: string } = {};
3837
private _piiPaths: string[];
38+
private _telemetryLevel: TelemetryLevel;
3939
private _sendErrorTelemetry: boolean;
4040

41-
public readonly telemetryLevel = new MutableObservableValue<TelemetryLevel>(TelemetryLevel.USAGE);
4241

4342
private readonly _disposables = new DisposableStore();
4443
private _cleanupPatterns: RegExp[] = [];
@@ -51,6 +50,7 @@ export class TelemetryService implements ITelemetryService {
5150
this._appenders = config.appenders;
5251
this._commonProperties = config.commonProperties || Promise.resolve({});
5352
this._piiPaths = config.piiPaths || [];
53+
this._telemetryLevel = TelemetryLevel.USAGE;
5454
this._sendErrorTelemetry = !!config.sendErrorTelemetry;
5555

5656
// static cleanup pattern for: `vscode-file:///DANGEROUS/PATH/resources/app/Useful/Information`
@@ -83,13 +83,17 @@ export class TelemetryService implements ITelemetryService {
8383
level = Math.min(level, maxCollectableTelemetryLevel);
8484
}
8585

86-
this.telemetryLevel.value = level;
86+
this._telemetryLevel = level;
8787
}
8888

8989
get sendErrorTelemetry(): boolean {
9090
return this._sendErrorTelemetry;
9191
}
9292

93+
get telemetryLevel(): TelemetryLevel {
94+
return this._telemetryLevel;
95+
}
96+
9397
async getTelemetryInfo(): Promise<ITelemetryInfo> {
9498
const values = await this._commonProperties;
9599

@@ -108,7 +112,7 @@ export class TelemetryService implements ITelemetryService {
108112

109113
private _log(eventName: string, eventLevel: TelemetryLevel, data?: ITelemetryData): Promise<any> {
110114
// don't send events when the user is optout
111-
if (this.telemetryLevel.value < eventLevel) {
115+
if (this._telemetryLevel < eventLevel) {
112116
return Promise.resolve(undefined);
113117
}
114118

src/vs/platform/telemetry/common/telemetryUtils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { IDisposable } from 'vs/base/common/lifecycle';
77
import { cloneAndChange, safeStringify } from 'vs/base/common/objects';
8-
import { staticObservableValue } from 'vs/base/common/observableValue';
98
import { isObject } from 'vs/base/common/types';
109
import { URI } from 'vs/base/common/uri';
1110
import { ConfigurationTarget, ConfigurationTargetToString, IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -42,7 +41,7 @@ export class NullTelemetryServiceShape implements ITelemetryService {
4241
}
4342

4443
setExperimentProperty() { }
45-
telemetryLevel = staticObservableValue(TelemetryLevel.NONE);
44+
telemetryLevel = TelemetryLevel.NONE;
4645
getTelemetryInfo(): Promise<ITelemetryInfo> {
4746
return Promise.resolve({
4847
instanceId: 'someValue.instanceId',

src/vs/platform/telemetry/test/browser/telemetryService.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,15 +800,15 @@ suite('TelemetryService', () => {
800800
}
801801
}(), TestProductService);
802802

803-
assert.strictEqual(service.telemetryLevel.value, TelemetryLevel.NONE);
803+
assert.strictEqual(service.telemetryLevel, TelemetryLevel.NONE);
804804

805805
telemetryLevel = TelemetryConfiguration.ON;
806806
emitter.fire({});
807-
assert.strictEqual(service.telemetryLevel.value, TelemetryLevel.USAGE);
807+
assert.strictEqual(service.telemetryLevel, TelemetryLevel.USAGE);
808808

809809
telemetryLevel = TelemetryConfiguration.ERROR;
810810
emitter.fire({});
811-
assert.strictEqual(service.telemetryLevel.value, TelemetryLevel.ERROR);
811+
assert.strictEqual(service.telemetryLevel, TelemetryLevel.ERROR);
812812

813813
service.dispose();
814814
});

src/vs/workbench/api/browser/mainThreadTelemetry.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Disposable } from 'vs/base/common/lifecycle';
7+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
78
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
89
import { IProductService } from 'vs/platform/product/common/productService';
910
import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings';
10-
import { ITelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
11+
import { ITelemetryService, TelemetryLevel, TELEMETRY_OLD_SETTING_ID, TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry';
1112
import { isLoggingOnly, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
1213
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
1314
import { ExtHostContext, ExtHostTelemetryShape, MainContext, MainThreadTelemetryShape } from '../common/extHost.protocol';
@@ -21,6 +22,7 @@ export class MainThreadTelemetry extends Disposable implements MainThreadTelemet
2122
constructor(
2223
extHostContext: IExtHostContext,
2324
@ITelemetryService private readonly _telemetryService: ITelemetryService,
25+
@IConfigurationService private readonly _configurationService: IConfigurationService,
2426
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
2527
@IProductService private readonly _productService: IProductService,
2628
) {
@@ -29,8 +31,10 @@ export class MainThreadTelemetry extends Disposable implements MainThreadTelemet
2931
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTelemetry);
3032

3133
if (supportsTelemetry(this._productService, this._environmentService)) {
32-
this._register(_telemetryService.telemetryLevel.onDidChange(level => {
33-
this._proxy.$onDidChangeTelemetryLevel(level);
34+
this._register(this._configurationService.onDidChangeConfiguration(e => {
35+
if (e.affectsConfiguration(TELEMETRY_SETTING_ID) || e.affectsConfiguration(TELEMETRY_OLD_SETTING_ID)) {
36+
this._proxy.$onDidChangeTelemetryLevel(this.telemetryLevel);
37+
}
3438
}));
3539
}
3640
const loggingOnly = isLoggingOnly(this._productService, this._environmentService);
@@ -42,7 +46,7 @@ export class MainThreadTelemetry extends Disposable implements MainThreadTelemet
4246
return TelemetryLevel.NONE;
4347
}
4448

45-
return this._telemetryService.telemetryLevel.value;
49+
return this._telemetryService.telemetryLevel;
4650
}
4751

4852
$publicLog(eventName: string, data: any = Object.create(null)): void {

src/vs/workbench/browser/web.api.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import type { IProductConfiguration } from 'vs/base/common/product';
1515
import type { ICredentialsProvider } from 'vs/platform/credentials/common/credentials';
1616
import type { TunnelProviderFeatures } from 'vs/platform/tunnel/common/tunnel';
1717
import type { IProgress, IProgressCompositeOptions, IProgressDialogOptions, IProgressNotificationOptions, IProgressOptions, IProgressStep, IProgressWindowOptions } from 'vs/platform/progress/common/progress';
18-
import type { IObservableValue } from 'vs/base/common/observableValue';
19-
import type { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
2018
import type { ITextEditorOptions } from 'vs/platform/editor/common/editor';
2119
import type { EditorGroupLayout } from 'vs/workbench/services/editor/common/editorGroupsService';
2220

@@ -77,11 +75,6 @@ export interface IWorkbench {
7775
* workbench.
7876
*/
7977
openUri(target: URI): Promise<boolean>;
80-
81-
/**
82-
* Current workbench telemetry level.
83-
*/
84-
readonly telemetryLevel: IObservableValue<TelemetryLevel>;
8578
};
8679

8780
window: {

src/vs/workbench/browser/web.factory.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
1313
import { DeferredPromise } from 'vs/base/common/async';
1414
import { asArray } from 'vs/base/common/arrays';
1515
import { IProgress, IProgressCompositeOptions, IProgressDialogOptions, IProgressNotificationOptions, IProgressOptions, IProgressStep, IProgressWindowOptions } from 'vs/platform/progress/common/progress';
16-
import { IObservableValue } from 'vs/base/common/observableValue';
17-
import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
1816
import { LogLevel } from 'vs/platform/log/common/log';
1917

2018
let created = false;
@@ -133,11 +131,6 @@ export namespace env {
133131

134132
return workbench.env.openUri(target);
135133
}
136-
137-
/**
138-
* {@linkcode IWorkbench.env IWorkbench.env.telemetryLevel}
139-
*/
140-
export const telemetryLevel: Promise<IObservableValue<TelemetryLevel>> = workbenchPromise.p.then(workbench => workbench.env.telemetryLevel);
141134
}
142135

143136
export namespace window {

src/vs/workbench/browser/web.main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ export class BrowserMain extends Disposable {
138138
const timerService = accessor.get(ITimerService);
139139
const openerService = accessor.get(IOpenerService);
140140
const productService = accessor.get(IProductService);
141-
const telemetryService = accessor.get(ITelemetryService);
142141
const progressService = accessor.get(IProgressService);
143142
const environmentService = accessor.get(IBrowserWorkbenchEnvironmentService);
144143
const instantiationService = accessor.get(IInstantiationService);
@@ -152,7 +151,6 @@ export class BrowserMain extends Disposable {
152151
executeCommand: (command, ...args) => commandService.executeCommand(command, ...args)
153152
},
154153
env: {
155-
telemetryLevel: telemetryService.telemetryLevel,
156154
async getUriScheme(): Promise<string> {
157155
return productService.urlProtocol;
158156
},

0 commit comments

Comments
 (0)