proxy-any

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i proxy-any

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • lixinliang