1

I'm in the middle of an ember 1.12.1 -> 1.13.11 and ember data 1.0.0-beta.19.1 -> 1.13.15 update. I previously had a template:

{{a-component parent=model.parent}}

and a component

parentChanged: on('init', observer('parent', function() {
  var parent = this.get('parent');
  if (parent) {
    parent.get('child').then(child => {
      this.set('child', child);
    });
  }
}))

This worked previously, but after the update, child is undefined after the then call. I had to change it to

parentChanged: on('init', observer('parent', function() {
  var parent = this.get('parent');
  if (parent) {
    parent.then(parent => {
      parent.get('child').then(child => {
        this.set('child', child);
      });
    });
  }
}))

to get it back to working like before the update.

Does anyone know why this is? It seems like the template stops resolving promises after the update.

real_ate
  • 10,861
  • 3
  • 27
  • 48
Kelly Selden
  • 1,238
  • 11
  • 21
  • 1
    My bet is on undocumented behavior I don't think the first version should ever work since you're passing the promise to a component, and you're not using it in the template so it doesn't wait for it to resolve so it can render the promise. Also maybe not related but my recommendation would be to have all of the promise handling stuff in the controller/route (or component) which the `{{a-component}}` lives in. So that the `a-component` already get's a resolved value and not a promise. Will probably make your life easier. – Piotr Dec 17 '15 at 17:12
  • I am very in agreement this code needs a refactor. So if I would have had something else in the template like `{{b-component child=model.parent.child}}`, it might have worked as a side effect of the other component? – Kelly Selden Dec 17 '15 at 17:29
  • It might work, no idea :) I didn't really rely on this behavior at all, rather optet to handle the promises in the router or parent components, but you might try it would be interested in the result if you can post back. – Piotr Dec 17 '15 at 17:43
  • I always thought that if you end in a promise when supplying to a component, it would be resolved by the time it reaches component code, but it may have been doing that by accident and trolling me all this time! – Kelly Selden Dec 17 '15 at 17:53
  • If you pass a promise to a component it receives a promise (just like with every other value if you don't use helpers since they can change the value) the value doesn't change in between. Afaik only if you use it in the template (so `{{promise.name}}`) ember implicitly waits for the promise to resolve and tries to use it. – Piotr Dec 17 '15 at 18:36

1 Answers1

1

crosslink https://github.com/emberjs/ember.js/issues/12732

So after some digging and a repro http://emberjs.jsbin.com/ququdenari/edit?html,js,output, I can't get the initial working case in 1.12.1 working with just promises. This leads me to believe that it may have been the way ember-data was setting up the relationship promises, and since I was updating from 1.0.0-beta.19.1 to 1.13.15, any breaking change is fair game.

In conclusion, I better understand the issue which was my goal.

Edit:

I made an addon ember-resolve-promise-helper to help abstract this issue out of your code.

Kelly Selden
  • 1,238
  • 11
  • 21