deferred-proxy-chain
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

deferred-proxy-chain

Allows collecting chained calls that are evaluated asynchronously when the target object arrives

How to use

    const deferred = new DeferredChain();
    const doSomething = deferred.getProxy().field.nested.doSomething;
    const target = {
      field: {
        nested: {
          doSomething() {
            return 'something';
          },
        },
      },
    };
    deferred.setTarget(target);
    
    const result = doSomething();
 
    expect(result).toEqual('something');

Requirements

Features

  • allows performing property chain or even method calls on nonexistent objects
  • on chain can be executed against different target objects (calling setTarget multiple times)
  • methods called in the chain are executed with the correct this object

Limitations

  • doesn't support calls that resolves to a primitive value in the target object,
  • doesn't cache values returned by the functions and getters in the chain – each call executed since the target object has been set, causes execution of the methods used earlier in the chain

Package Sidebar

Install

npm i deferred-proxy-chain

Weekly Downloads

399

Version

0.0.2

License

MIT

Unpacked Size

43.8 kB

Total Files

22

Last publish

Collaborators

  • michalstocki