mc-beta-server/server/TrackedProperty.ts

23 lines
440 B
TypeScript
Raw Normal View History

export class TrackedProperty<T> {
private trackedValue?:T;
private updateCallback?:(value:T) => void;
constructor(initialValue?:T) {
this.trackedValue = initialValue;
}
public set OnChange(value:() => void) {
this.updateCallback = value;
}
public get Value() {
return this.trackedValue;
}
public set Value(value) {
this.trackedValue = value;
if (this.updateCallback && value) {
this.updateCallback(value);
}
}
}