Re:Write logic, not mechanics
by ricardobeat on Thursday April 19, 2012 @12:13PM
(#3863697)
That last line
Isn't exactly equivalent to the non-promise one, since now `Mustache.render` is async, is it?
[ Parent
| on HN ]
It's much more useful now, IMO. Now you can chain an error handler onto your view's render method, and the level of abstraction becomes "I couldn't render the view" rather than "I couldn't get some JSON from the server".
Functionally the behavior is the same - you're still going to have to gate an asynchronous stream of actions (make sure steps a, b, c have completed before d, etc.), but with this, you can describe that logic where it matters - renderView().then(attachHandlers).then..., instead of callback nesting hell (attachHandlers would have to be in renderView).
Yeah I had this comment there
// Assuming Mustache.render = promised(Mustache.render)
But my hope is that more libraries will be accepting promises in a future so one won't have to do the wrapping of a world around.