mc-beta-server/server/TrackedProperty.ts

23 lines
No EOL
448 B
TypeScript

export default 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);
}
}
}