Created
June 29, 2018 17:45
-
-
Save corbanbrook/162b38c9801949debce9f1ae1a8e59e1 to your computer and use it in GitHub Desktop.
proxy object
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
+class ProxyObject { | |
+ _target: Object | |
+ | |
+ constructor(target) { | |
+ this.proxy(target) | |
+ | |
+ Object.keys(target).forEach(key => { | |
+ Object.defineProperty(this, key, { | |
+ enumerable: true, | |
+ configurable: true, | |
+ get: () => { | |
+ console.log("getting proxied value for", key) | |
+ return this._target[key] | |
+ }, | |
+ set: (value: any) => { | |
+ console.log("setting proxied value for", key, value) | |
+ this._target[key] = value | |
+ } | |
+ }) | |
+ }) | |
+ } | |
+ | |
+ proxy(target) { | |
+ this._target = target | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment