Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
Why Stack Overflow recommends it
Stack Overflow users link it when explaining or trying to reproduce the generator-plus-promises pattern for flattening async JavaScript, such as using generators with Angular's $http service.
Recommended by 2 people across 2 different months, 2015 to 2017.
What it is
A short 2014 tutorial from LearnCode.academy on ES6 (Harmony) generators in JavaScript. It shows how pairing generators with a small helper library lets you write asynchronous code that reads like synchronous code, with a linked gist for the code.
What people said
Recommends Lyn · 2015-07 · Stack Overflow · on “how to render multiple views with their models from ajax calls in backbone”
First, pass a success (and error?) callback to the getFByBooking function, to align the interface with the model's getFById function. That way, you can treat them both in the same manner: getFByBooking : function(idBooking, context, success /*, error*/) { $.ajax({ // ... success: success }); } Now, in your router, you can pass the same success callback to them both, but keep it from being called on the first response. You could harness the power of underscore's/lodash's _.after [LINK] here: var success = _.bind(function (modelBooking, facturasCandidatas) { this.asociarF1BookingExito(facturasCandidatas); }, this); // let's tell it to only be invoked on the second call success = _.after(succes
Recommends prajnavantha · 2017-03 · Stack Overflow · on “Javascript: Weird syntactic element”
I would not like to read your code for you but i think, with a little help you could understand this code your self. I guess you need help with the various new syntax being used in the code above. I'll try to note down those so that you can understand all of this code yourself. (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function*{}) This line basically is similar to (0,x)(function*{}) where x is a function which takes a generator function as an argument. Whenever you have a line of the form (x,y) it will always return the last value. So in the case of(x,y) it will return y. If its (0,x) it will return x. Thus in code which you posted, the first line will return (_asyncToGe
Cites kybak · 2016-03 · Stack Overflow · on “ES6 Generator with $http service”
I'm trying to use the ES6 generator on the client side with the Angular $http service. I'd like to be able to use the $http service without the use of callbacks, if possible. Like: var gen = function* () { var test = yield $http.get('/test/'); console.log(test); }; var http = gen(); http.next(); http.next(); // returns undefined /// or /// var gen = function* () { yield $http.get('/test/'); }; console.log(http.next()); //returns a promise object which won't allow me to use the needed data The reason why I ask is because I'm trying to mimic this demonstration [this video] I'm just looking for the simplest, most straight forward approach. Any suggestions?