Skip to content

Instantly share code, notes, and snippets.

@gevgeny
Last active November 5, 2019 21:15
Show Gist options
  • Save gevgeny/d2666c30a906e3d8af742c107c761af7 to your computer and use it in GitHub Desktop.
Save gevgeny/d2666c30a906e3d8af742c107c761af7 to your computer and use it in GitHub Desktop.
function observable(target: any, propertyKey: string): PropertyDecorator {
return {
get(): any {
return this._value;
},
set(value: any) {
console.log(`Gotcha! value is ${value}.`);
this._value = value;
},
};
}
class State {
@observable foo;
}
const state1 = new State();
const state2 = new State();
state1.foo = 42; // set() is called
state2.foo = 73; // set() is called
console.log(state1.foo); // get() is called
console.log(state2.foo); // get() is called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment