1.0.0 • Published 7 years ago
proxy-any v1.0.0
proxy-any
Proxy all properties as anonymous function, including the properties and return value of this function.
Getting started
$ npm install --save proxy-any
Usage
import ProxyAny from 'proxy-any';
const sdk = new ProxyAny;
- What ever you type, always will work without error.
- No more to do any fallback in different environment.
import ProxyAny from 'proxy-any';
window.sdk = window.sdk || new ProxyAny;
sdk.component.confirm();
sdk.widget.create('loading').show();
Access unlimitedly
sdk.api.www.github.com;
sdk.table.user.name = 'lixinliang';
Invoke unlimitedly
sdk.say('i')('like')('currify')('!');
Chaining unlimitedly
sdk.query('#app').addClass('active').on(() => {});
Proxy handler
- Your fallback code could be written in handler.
ProxyAny.listen(sdk, ({ type, key, receiver, self, args }) => {
// getter
// setter
// caller
if (type == 'getter') {
return 'this is the correct value.';
}
});
Error handler
- Do some error report or debug.
ProxyAny.error = ({ err }) => {
console.error(err);
};
License
MIT
1.0.0
7 years ago