opset
Set of runnable interdependent operations
Example
var OpSet = ;var UserModel = ;var BlogModel = ; // declare set of interdependent operationsvar blog = 'blog'; blog; // already resolved values can be setted blog; blog; // run userPosts operation, returns a promiseblog; // handle results { console;} // handle errors { console;}
How to use
Install with NPM:
npm install --save opset
Then require it:
var OpSet = ;
API
OpSet(alias): constructor, create a new OpSet with an alias
To produce the instance, OpSet
should be called with new
operator.
var report = 'report';
set(token, value): alias for setCache() setCache(token, value): defines a resolved value for injection
Register the final value.
report;
op(token, factoryFn): alias for operation() operation(token, factoryFn): defines a operation that generates a value for injection
To produce the instance, factoryFn
will be called once (with instance context) and its result will be used.
The factoryFn
function arguments should be the tokens of the operations that we need resolved here.
report;
run(token): runs an operation, returns a promise
If any operation throws an error or gets rejected, and you omit the rejection handler, the execution will be stopped and error would be forwarded to this resultant promise.
// result is a promisevar myStats = report; // handle resultsmyStats; // handle errors, including those unhandled from inside operationsmyStats;