Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save corbanbrook/162b38c9801949debce9f1ae1a8e59e1 to your computer and use it in GitHub Desktop.
Save corbanbrook/162b38c9801949debce9f1ae1a8e59e1 to your computer and use it in GitHub Desktop.
proxy object
+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