Automatic promise unwrapping in template?


#1

I remember reading this somewhere before that Ember allows object properties to be set as a promise and the resolved value will get rendered into the template.

http://jsfiddle.net/B6fTE/

Did I do something wrong here?


#2

The templates don’t work with promises directly, they work with object proxies. You need to use a PromiseObject or PromiseArray, which have proxy functionality mixed in so the templates do update when the promise resolves.

But in your example, you don’t really need this, as Ember routing takes care of that for you. If you return a promise from the model hook of your ApplicationRoute, Ember will wait until the promise resolves before setting the model on your controller.


#3

Here is an example of how to use a PromiseObject http://jsfiddle.net/B6fTE/2/ (adapted based on https://github.com/emberjs/data/blob/52114c36457b73ed880562b4595482d8576f5826/packages/ember-data/lib/system/store.js#L1622)


#4

Ah, I see.

Thanks for all the responses! Even though that left me a bit disappointed. :frowning:


#5

Another approach without using PromiseObject instead a computed that wraps a Promise.

http://jsfiddle.net/B6fTE/7/ not exactly production-ready code… but it illustrates the idea.