Proxy any list of objects or functions to a single entity.
All common properties and methods are automatically reflected.
- Objects can be heterogeneous with a shared interface
- Can proxy a set of functions (sync/async) to a single call
- Works with Arrays
- Supports callbacks as arguments
- Excellent with async/await
- Tiny in size. Only 444 bytes gzipped
Install
Download the latest from dist folder
or from npm:
npm install --save proxly
Usage/Examples
Proxy Functions
{ return a + b; } { return a - b; } { return a * b; } async { let proxy = ; let result = await ; console; // [6, 2, 8]};
Proxy Objects
Objects could be instances of the same class or just any two objects with a common interface.
{ thisname = name; thiscount = 0; } { thiscount++; if thisname === 'add' return a + b; if thisname === 'subtract' return a - b; }let adder = 'add';let subtractor = 'subtract'; async { let proxy = ; console; // ["add", "subtract"] console; // [0, 0] console; // [14, 6] console; // [1, 1]};
Proxy Arrays
Of course it works with arrays
let fruits = "apple" "banana" "grape";let colors = "red" "yellow" "green";async { let proxy = ; console; // ["banana", "yellow"] console; // [3, 3] proxy; console; // [4, 4] console; // ["apple", "banana", "grape", "orange"] console; // ["red", "yellow", "green", "orange"]};
Callbacks
If a callback is passed into a proxied set of functions (or a method in a proxied set of objects), it is called back sequentially in the order the proxy was defined.
{ ;} { ;}async { let { console; }; let proxy = ; ;};
Output:
result 10
result 2
Examples
See the examples folder