Created
November 6, 2017 10:16
-
-
Save lifeart/3798ff6b6c79b5415737050958fdcd91 to your computer and use it in GitHub Desktop.
proxy-demo
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
import Ember from 'ember'; | |
const secondProxyMethods = { | |
get(target, prop) { | |
if (!window.counter) { | |
window.counter = 0; | |
} | |
console.log(`Чтение${a} ${prop}`); | |
window.counter++; | |
console.log(window.counter); | |
return target[prop]; | |
}, | |
set(target, prop, value) { | |
if (prop !== '_super') { | |
console.log(`Запись${a} ${prop} ${value}`); | |
} | |
target[prop] = value; | |
return true; | |
} | |
}; | |
const firstProxyMethods = { | |
get(target, prop) { | |
if (prop === 'create') { | |
return function(...args) { | |
console.log(args); | |
return new window['Proxy'](target[prop].apply(target,args), secondProxyMethods); | |
} | |
} | |
console.log(`Чтение ${prop}`); | |
return target[prop]; | |
}, | |
set(target, prop, value) { | |
console.log(`Запись ${prop} ${value}`); | |
target[prop] = value; | |
return true; | |
} | |
}; | |
export default new Proxy(Ember.Component.extend({}),firstProxyMethods); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment