Skip to content

Commit bd8ade5

Browse files
authored
improves observable dev tools (microsoft#254942)
1 parent e3d6829 commit bd8ade5

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/vs/base/common/observableInternal/logging/debugger/debuggerApi.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ export type ObsDebuggerApi = {
2424
getDerivedInfo(instanceId: ObsInstanceId): IDerivedObservableDetailedInfo;
2525
getAutorunInfo(instanceId: ObsInstanceId): IAutorunDetailedInfo;
2626
getObservableValueInfo(instanceId: ObsInstanceId): IObservableValueInfo;
27+
2728
setValue(instanceId: ObsInstanceId, jsonValue: unknown): void;
2829
getValue(instanceId: ObsInstanceId): unknown;
2930

31+
// For autorun and deriveds
32+
rerun(instanceId: ObsInstanceId): void;
33+
34+
logValue(instanceId: ObsInstanceId): void;
35+
3036
getTransactionState(): ITransactionState | undefined;
3137
}
3238
};

src/vs/base/common/observableInternal/logging/debugger/devToolsLogger.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,25 @@ export class DevToolsLogger implements IObservableLogger {
135135
}
136136

137137
return undefined;
138-
}
138+
},
139+
logValue: (instanceId) => {
140+
const obs = this._aliveInstances.get(instanceId);
141+
if (obs && 'get' in obs) {
142+
console.log('Logged Value:', obs.get());
143+
} else {
144+
throw new BugIndicatingError('Observable is not supported');
145+
}
146+
},
147+
rerun: (instanceId) => {
148+
const obs = this._aliveInstances.get(instanceId);
149+
if (obs instanceof Derived) {
150+
obs.debugRecompute();
151+
} else if (obs instanceof AutorunObserver) {
152+
obs.debugRerun();
153+
} else {
154+
throw new BugIndicatingError('Observable is not supported');
155+
}
156+
},
139157
}
140158
};
141159
});

src/vs/base/common/observableInternal/observables/derivedImpl.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ export class Derived<T, TChangeSummary = any, TChange = void> extends BaseObserv
400400
this._value = newValue as any;
401401
}
402402

403+
public debugRecompute(): void {
404+
if (!this._isComputing) {
405+
this._recompute();
406+
} else {
407+
this._state = DerivedState.stale;
408+
}
409+
}
410+
403411
public setValue(newValue: T, tx: ITransaction, change: TChange): void {
404412
this._value = newValue;
405413
const observers = this._observers;

0 commit comments

Comments
 (0)