Last active
November 5, 2019 21:15
-
-
Save gevgeny/d2666c30a906e3d8af742c107c761af7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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