npm.io
1.0.0 • Published 4 years ago

proxy-any

Licence
MIT
Version
1.0.0
Deps
0
Vulns
0
Weekly
0

npm npm npm Travis CI Twitter

proxy-any

Proxy all properties as anonymous function, including the properties and return value of this function.

Getting started

$ npm install --save proxy-any

→ online playground

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