Skip to content

Commit 8e9e079

Browse files
Add a basic "disableable" class.
1 parent c6da5fd commit 8e9e079

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/client/common/utils/misc.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,34 @@ type DeepReadonlyObject<T> = {
5555
};
5656
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
5757

58+
/**
59+
* An object that can be disabled.
60+
*/
61+
export class Disableable {
62+
private enabled = true;
63+
64+
/**
65+
* True if the watcher is currently enabled.
66+
*/
67+
public get isEnabled(): boolean {
68+
return this.enabled;
69+
}
70+
71+
/**
72+
* Ensure that the watcher is enabled.
73+
*/
74+
public enable() {
75+
this.enabled = true;
76+
}
77+
78+
/**
79+
* Ensure that the watcher is disabled.
80+
*/
81+
public disable() {
82+
this.enabled = false;
83+
}
84+
}
85+
5886
// Information about a traced function/method call.
5987
export type TraceInfo = {
6088
elapsed: number; // milliseconds

0 commit comments

Comments
 (0)