Last active
July 10, 2019 18:54
-
-
Save meftunca/67b168fafd0d2b671cd5ae8a65adb1d0 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
export default listenerFunc => { | |
Object.defineProperty(window.globalStore, "onChangeListener", { | |
value: listenerFunc | |
}); | |
}; |
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
let Person = { | |
name: "test", | |
age: "12" | |
} |
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
window.globalStore = new Proxy( | |
person, | |
{ | |
get: function(target, value, r) { | |
return value in target ? target[value] : undefined; | |
}, | |
set: function(target, key, value, r) { | |
target[key] = value; | |
r.onChangeListener({ [key]: value }); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment