3 ms·
ember-data is a great example of why promises can be useful. When a view is loaded you query your server for the model(via ember-data's api), but at this point
by ollysb 13y ago
ember-data is a great example of why promises can be useful. When a view is loaded you query your server for the model(via ember-data's api), but at this point what you get is a graph of unresolved promises. It then gets passed through to the controllers/templates etc. which render immediately but are then updated automatically as soon as the promises resolve. This is the real value of promises, you can pass them around your app before they're resolved.
- sanderjd 13y agoYep, doing much the same thing in angularjs as we speak. It works very nicely and would have been a pain with only callbacks.
- tyleregeto 13y ago(Note: I haven't worked with Ember, and this probably doesn't jive with how they do things) This sounds a lot like traditional async Model/View programming. I've traditionally passed a model around, and use subscriptions to listen for "data." That has the added benefit of being reusable, with the model dispatching change events. Promises in this case sound like they are fulfilling a similar role by your description.