Usage
npm install async-promise-proxy
GeneratorToPromise
Used to wraps a es6 class that has generator methods, and proxies it into a promise. This is better expained with an example:
es6 exmpale
;; // NOTE this example is just to show case the yield -> then functionality. This is not a great use-case. * { // in this instance think of yield* like await in the async/await C# 6. let user = req; return user; } * { // one yield req; // two yield, this will be the data in the .then(function(data) { }) return req; } // now we user the generator: var userApi = ; // Now the calls to the generators will instead return promises.userApi userApi ; // You can even chain methods together:someFakeApi // you can even chain off the thens ;
NoMethodCatcher
Inherit from this class to setup a noSuchMethod like behavior in your class. Note this only works with node/io.js/)any server side js engine that supports the Proxy behavior). For node.js however you don't need to run with the --harmony-proxies flag, including the library does that for you.
es6 example:
; // class // these classes need constructors { super; // call super(true) if your catch-all method is a generator. this; // this is SUPER important, you must return this.proxy(). return this; } // name will be the name of the unhandled method that got called, args is...the args. { console; } { console; //note: if you want a fluent interface you have to return this.proxy() and not this return this; } var test = ; test // --> got unhandled method: someMethodThatDoesntExist with args does, not, existtest // --> Got a call on the actual method. // --> got unhandled method: soWhat with args ever
es5 example:
var NoMethodCatcher = NoMethodCatcher; { this; return this;}; // the only real difference.IAcceptAllMethodsprototype = ; IAcceptAllMethodsprototype { console;}; IAcceptAllMethodsprototype { console; //note: if you want a fluent interface you have to return this.proxy() and not this return this;}; var test = ; test // --> got unhandled method: someMethodThatDoesntExist with args does, not, existtest // --> Got a call on the actual method. // --> got unhandled method: soWhat with args ever