then() returning a null value when it should be pending












0















Ember 2.17



I am calling an helper from my template :



{{#each invoice.invoiceLines as |line| }}
{{pricings/full-pricing line.pricing}}
{{/each}}


invoice,invoiceLine, as well as pricing are ember models.



Here is how invoice is created in model () :



model(params) {
let invoice= this.store.findRecord('invoice',params.invoice_id)
return Ember.RSVP.hash({
invoice: invoice,
allShares: invoice.then((i)=>{return i.allShares()}),
detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


The goal of the helper is to take pricing, extract numbers (everything is in the model, no more relations) and return a string formatting the initial price and the subscription price.
The helper is as following :



import { helper } from '@ember/component/helper';

export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}
export default helper(pricingsFullPricing);


When I run the page, debugger is called twice (the template loop run once).



First time p is null, the second time it is a pricing.



Isn't then supposed to prevent that? Why does it behave like that?










share|improve this question

























  • what is the file location of your helper?

    – NullVoxPopuli
    Nov 28 '18 at 18:51











  • helpers/pricings/full-pricing.js

    – Syl
    Nov 28 '18 at 18:53













  • what is the value of invoice.invoiceLines? before your loop, can you put {{log invoice.invoiceLines}} and {{debugger}} in the template?

    – NullVoxPopuli
    Nov 28 '18 at 18:57











  • log of invoice.inlines : i.imgur.com/BTLEMQD.png

    – Syl
    Nov 28 '18 at 19:01













  • hmm, I don't know what any of that is -- can you use this? github.com/fivetanley/ember-promise-helpers and then work with a more regular object after it's awaited?

    – NullVoxPopuli
    Nov 28 '18 at 19:03
















0















Ember 2.17



I am calling an helper from my template :



{{#each invoice.invoiceLines as |line| }}
{{pricings/full-pricing line.pricing}}
{{/each}}


invoice,invoiceLine, as well as pricing are ember models.



Here is how invoice is created in model () :



model(params) {
let invoice= this.store.findRecord('invoice',params.invoice_id)
return Ember.RSVP.hash({
invoice: invoice,
allShares: invoice.then((i)=>{return i.allShares()}),
detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


The goal of the helper is to take pricing, extract numbers (everything is in the model, no more relations) and return a string formatting the initial price and the subscription price.
The helper is as following :



import { helper } from '@ember/component/helper';

export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}
export default helper(pricingsFullPricing);


When I run the page, debugger is called twice (the template loop run once).



First time p is null, the second time it is a pricing.



Isn't then supposed to prevent that? Why does it behave like that?










share|improve this question

























  • what is the file location of your helper?

    – NullVoxPopuli
    Nov 28 '18 at 18:51











  • helpers/pricings/full-pricing.js

    – Syl
    Nov 28 '18 at 18:53













  • what is the value of invoice.invoiceLines? before your loop, can you put {{log invoice.invoiceLines}} and {{debugger}} in the template?

    – NullVoxPopuli
    Nov 28 '18 at 18:57











  • log of invoice.inlines : i.imgur.com/BTLEMQD.png

    – Syl
    Nov 28 '18 at 19:01













  • hmm, I don't know what any of that is -- can you use this? github.com/fivetanley/ember-promise-helpers and then work with a more regular object after it's awaited?

    – NullVoxPopuli
    Nov 28 '18 at 19:03














0












0








0








Ember 2.17



I am calling an helper from my template :



{{#each invoice.invoiceLines as |line| }}
{{pricings/full-pricing line.pricing}}
{{/each}}


invoice,invoiceLine, as well as pricing are ember models.



Here is how invoice is created in model () :



model(params) {
let invoice= this.store.findRecord('invoice',params.invoice_id)
return Ember.RSVP.hash({
invoice: invoice,
allShares: invoice.then((i)=>{return i.allShares()}),
detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


The goal of the helper is to take pricing, extract numbers (everything is in the model, no more relations) and return a string formatting the initial price and the subscription price.
The helper is as following :



import { helper } from '@ember/component/helper';

export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}
export default helper(pricingsFullPricing);


When I run the page, debugger is called twice (the template loop run once).



First time p is null, the second time it is a pricing.



Isn't then supposed to prevent that? Why does it behave like that?










share|improve this question
















Ember 2.17



I am calling an helper from my template :



{{#each invoice.invoiceLines as |line| }}
{{pricings/full-pricing line.pricing}}
{{/each}}


invoice,invoiceLine, as well as pricing are ember models.



Here is how invoice is created in model () :



model(params) {
let invoice= this.store.findRecord('invoice',params.invoice_id)
return Ember.RSVP.hash({
invoice: invoice,
allShares: invoice.then((i)=>{return i.allShares()}),
detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


The goal of the helper is to take pricing, extract numbers (everything is in the model, no more relations) and return a string formatting the initial price and the subscription price.
The helper is as following :



import { helper } from '@ember/component/helper';

export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}
export default helper(pricingsFullPricing);


When I run the page, debugger is called twice (the template loop run once).



First time p is null, the second time it is a pricing.



Isn't then supposed to prevent that? Why does it behave like that?







javascript ember.js promise ember-data






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 10:27







Syl

















asked Nov 28 '18 at 18:46









SylSyl

1,77952852




1,77952852













  • what is the file location of your helper?

    – NullVoxPopuli
    Nov 28 '18 at 18:51











  • helpers/pricings/full-pricing.js

    – Syl
    Nov 28 '18 at 18:53













  • what is the value of invoice.invoiceLines? before your loop, can you put {{log invoice.invoiceLines}} and {{debugger}} in the template?

    – NullVoxPopuli
    Nov 28 '18 at 18:57











  • log of invoice.inlines : i.imgur.com/BTLEMQD.png

    – Syl
    Nov 28 '18 at 19:01













  • hmm, I don't know what any of that is -- can you use this? github.com/fivetanley/ember-promise-helpers and then work with a more regular object after it's awaited?

    – NullVoxPopuli
    Nov 28 '18 at 19:03



















  • what is the file location of your helper?

    – NullVoxPopuli
    Nov 28 '18 at 18:51











  • helpers/pricings/full-pricing.js

    – Syl
    Nov 28 '18 at 18:53













  • what is the value of invoice.invoiceLines? before your loop, can you put {{log invoice.invoiceLines}} and {{debugger}} in the template?

    – NullVoxPopuli
    Nov 28 '18 at 18:57











  • log of invoice.inlines : i.imgur.com/BTLEMQD.png

    – Syl
    Nov 28 '18 at 19:01













  • hmm, I don't know what any of that is -- can you use this? github.com/fivetanley/ember-promise-helpers and then work with a more regular object after it's awaited?

    – NullVoxPopuli
    Nov 28 '18 at 19:03

















what is the file location of your helper?

– NullVoxPopuli
Nov 28 '18 at 18:51





what is the file location of your helper?

– NullVoxPopuli
Nov 28 '18 at 18:51













helpers/pricings/full-pricing.js

– Syl
Nov 28 '18 at 18:53







helpers/pricings/full-pricing.js

– Syl
Nov 28 '18 at 18:53















what is the value of invoice.invoiceLines? before your loop, can you put {{log invoice.invoiceLines}} and {{debugger}} in the template?

– NullVoxPopuli
Nov 28 '18 at 18:57





what is the value of invoice.invoiceLines? before your loop, can you put {{log invoice.invoiceLines}} and {{debugger}} in the template?

– NullVoxPopuli
Nov 28 '18 at 18:57













log of invoice.inlines : i.imgur.com/BTLEMQD.png

– Syl
Nov 28 '18 at 19:01







log of invoice.inlines : i.imgur.com/BTLEMQD.png

– Syl
Nov 28 '18 at 19:01















hmm, I don't know what any of that is -- can you use this? github.com/fivetanley/ember-promise-helpers and then work with a more regular object after it's awaited?

– NullVoxPopuli
Nov 28 '18 at 19:03





hmm, I don't know what any of that is -- can you use this? github.com/fivetanley/ember-promise-helpers and then work with a more regular object after it's awaited?

– NullVoxPopuli
Nov 28 '18 at 19:03












2 Answers
2






active

oldest

votes


















2














Your route is wrong, routes are promise aware (that's what hash is for), it should be:



model(params) {
return Ember.RSVP.hash({
invoice: this.store.findRecord('invoice',params.invoice_id)
//allShares: invoice.then((i)=>{return i.allShares()}),
//detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


Then your handlebars is just:



{{#each model.invoice.invoiceLines as |line| }}
{{line}}
{{/each}}


You also shouldn't call methods like you are on a model. It's not really clear what allShares(), etc does but these should (probably) be computed in the controller. Something along the lines of:



import { computed } from '@ember/object';

export default Controller.extend({
allShares:computed('model.invoice', function(){
return this.get('model.invoice').allShares();
});
});


Though this doesn't seem ideal. Like I said, it's hard to be explicit as it's not clear what your trying to do here. It'd probably make more sense if your extracted these methods into a service.



You then don't need the helper at all. This appears to be just trying to work around promises.



It makes life a lot easier if you try and load all server side data in the route before load.






share|improve this answer


























  • The share functions are not related to my problem, but thanks for the input. It is custom model function that are used to retrieve tabular data related to the model. I end up displaying them in tables.

    – Syl
    Nov 29 '18 at 10:29






  • 1





    @Syl But the whole reason you've structured your route the way you have is because of the share functions. Ultimately that is the design decision that has caused this issue. This is essentially an XY Problem

    – Liam
    Nov 29 '18 at 10:32













  • What happen when I get null is that it solve the hash and return null because the second promise (invoice as a variable) should have been called inside the RSVP hash ?

    – Syl
    Nov 29 '18 at 10:41













  • if (model.invoice !== null) seems like the obvious solution

    – Liam
    Nov 29 '18 at 10:42








  • 1





    Or even just get your invoice call to return all the data you need in one go. Without multiple hops to the server. If allShares needs an invoice you could easily argue that it is part of invoice and should be loaded with it

    – Liam
    Nov 29 '18 at 10:46



















2














First rule of helpers




Each time the input to a helper changes, the compute function will be called again.




Second, there's nothing about helpers that will make this block subsequent calls because you are returning a promise.



export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}


You've created a simple helper here that will use the promise itself as the value. Look at ember-promise-helpers/await to see how a class based helper is used to manually set the value that's displayed in the template.



Now, if you're wondering why the recomputation is happening, I'm going to have to speculate based off the knowledge I have of Ember data just from being part of the Ember community (I've never actually used Ember Data). You know line.pricing is a promise? I can then assume your using some sort of relationship, which will most likely have to be loaded via an ajax call (hence the promise). But these relationships in Ember data, iirc, use this PromiseProxyMixin that allow them to behave simultaneously like a promise or like an object (depending on whether the data is in the store already or not). This is what allows you to reference the promise in your template without then



See this article for a better understanding of what I mean






share|improve this answer



















  • 1





    I've never actually used Ember Data that is the best way to be. Worst part of Ember IMO

    – Liam
    Nov 29 '18 at 10:30











  • It wasn't 1.0 when I started Ember. Nowadays, I think ED has done a very good job solving this difficult problem in a general way. I just still find the benefit to complexity ratio heavily skewed in the direction of "do I really need a full fledged client side ORM?" I use semantically named services + my own relationship aware recursive deserializers/serializers + a promise returning wrapper "rest-client" that makes the http requests and knows how to communicate with my backend. Any new Ember dev that knows js groks the architecture without trying b/c its so explicit

    – mistahenry
    Nov 29 '18 at 10:40












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526134%2fthen-returning-a-null-value-when-it-should-be-pending%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Your route is wrong, routes are promise aware (that's what hash is for), it should be:



model(params) {
return Ember.RSVP.hash({
invoice: this.store.findRecord('invoice',params.invoice_id)
//allShares: invoice.then((i)=>{return i.allShares()}),
//detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


Then your handlebars is just:



{{#each model.invoice.invoiceLines as |line| }}
{{line}}
{{/each}}


You also shouldn't call methods like you are on a model. It's not really clear what allShares(), etc does but these should (probably) be computed in the controller. Something along the lines of:



import { computed } from '@ember/object';

export default Controller.extend({
allShares:computed('model.invoice', function(){
return this.get('model.invoice').allShares();
});
});


Though this doesn't seem ideal. Like I said, it's hard to be explicit as it's not clear what your trying to do here. It'd probably make more sense if your extracted these methods into a service.



You then don't need the helper at all. This appears to be just trying to work around promises.



It makes life a lot easier if you try and load all server side data in the route before load.






share|improve this answer


























  • The share functions are not related to my problem, but thanks for the input. It is custom model function that are used to retrieve tabular data related to the model. I end up displaying them in tables.

    – Syl
    Nov 29 '18 at 10:29






  • 1





    @Syl But the whole reason you've structured your route the way you have is because of the share functions. Ultimately that is the design decision that has caused this issue. This is essentially an XY Problem

    – Liam
    Nov 29 '18 at 10:32













  • What happen when I get null is that it solve the hash and return null because the second promise (invoice as a variable) should have been called inside the RSVP hash ?

    – Syl
    Nov 29 '18 at 10:41













  • if (model.invoice !== null) seems like the obvious solution

    – Liam
    Nov 29 '18 at 10:42








  • 1





    Or even just get your invoice call to return all the data you need in one go. Without multiple hops to the server. If allShares needs an invoice you could easily argue that it is part of invoice and should be loaded with it

    – Liam
    Nov 29 '18 at 10:46
















2














Your route is wrong, routes are promise aware (that's what hash is for), it should be:



model(params) {
return Ember.RSVP.hash({
invoice: this.store.findRecord('invoice',params.invoice_id)
//allShares: invoice.then((i)=>{return i.allShares()}),
//detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


Then your handlebars is just:



{{#each model.invoice.invoiceLines as |line| }}
{{line}}
{{/each}}


You also shouldn't call methods like you are on a model. It's not really clear what allShares(), etc does but these should (probably) be computed in the controller. Something along the lines of:



import { computed } from '@ember/object';

export default Controller.extend({
allShares:computed('model.invoice', function(){
return this.get('model.invoice').allShares();
});
});


Though this doesn't seem ideal. Like I said, it's hard to be explicit as it's not clear what your trying to do here. It'd probably make more sense if your extracted these methods into a service.



You then don't need the helper at all. This appears to be just trying to work around promises.



It makes life a lot easier if you try and load all server side data in the route before load.






share|improve this answer


























  • The share functions are not related to my problem, but thanks for the input. It is custom model function that are used to retrieve tabular data related to the model. I end up displaying them in tables.

    – Syl
    Nov 29 '18 at 10:29






  • 1





    @Syl But the whole reason you've structured your route the way you have is because of the share functions. Ultimately that is the design decision that has caused this issue. This is essentially an XY Problem

    – Liam
    Nov 29 '18 at 10:32













  • What happen when I get null is that it solve the hash and return null because the second promise (invoice as a variable) should have been called inside the RSVP hash ?

    – Syl
    Nov 29 '18 at 10:41













  • if (model.invoice !== null) seems like the obvious solution

    – Liam
    Nov 29 '18 at 10:42








  • 1





    Or even just get your invoice call to return all the data you need in one go. Without multiple hops to the server. If allShares needs an invoice you could easily argue that it is part of invoice and should be loaded with it

    – Liam
    Nov 29 '18 at 10:46














2












2








2







Your route is wrong, routes are promise aware (that's what hash is for), it should be:



model(params) {
return Ember.RSVP.hash({
invoice: this.store.findRecord('invoice',params.invoice_id)
//allShares: invoice.then((i)=>{return i.allShares()}),
//detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


Then your handlebars is just:



{{#each model.invoice.invoiceLines as |line| }}
{{line}}
{{/each}}


You also shouldn't call methods like you are on a model. It's not really clear what allShares(), etc does but these should (probably) be computed in the controller. Something along the lines of:



import { computed } from '@ember/object';

export default Controller.extend({
allShares:computed('model.invoice', function(){
return this.get('model.invoice').allShares();
});
});


Though this doesn't seem ideal. Like I said, it's hard to be explicit as it's not clear what your trying to do here. It'd probably make more sense if your extracted these methods into a service.



You then don't need the helper at all. This appears to be just trying to work around promises.



It makes life a lot easier if you try and load all server side data in the route before load.






share|improve this answer















Your route is wrong, routes are promise aware (that's what hash is for), it should be:



model(params) {
return Ember.RSVP.hash({
invoice: this.store.findRecord('invoice',params.invoice_id)
//allShares: invoice.then((i)=>{return i.allShares()}),
//detailShares: invoice.then((i)=>{return i.detailShares()})
});
}


Then your handlebars is just:



{{#each model.invoice.invoiceLines as |line| }}
{{line}}
{{/each}}


You also shouldn't call methods like you are on a model. It's not really clear what allShares(), etc does but these should (probably) be computed in the controller. Something along the lines of:



import { computed } from '@ember/object';

export default Controller.extend({
allShares:computed('model.invoice', function(){
return this.get('model.invoice').allShares();
});
});


Though this doesn't seem ideal. Like I said, it's hard to be explicit as it's not clear what your trying to do here. It'd probably make more sense if your extracted these methods into a service.



You then don't need the helper at all. This appears to be just trying to work around promises.



It makes life a lot easier if you try and load all server side data in the route before load.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 29 '18 at 10:22

























answered Nov 29 '18 at 10:11









LiamLiam

16.4k1678131




16.4k1678131













  • The share functions are not related to my problem, but thanks for the input. It is custom model function that are used to retrieve tabular data related to the model. I end up displaying them in tables.

    – Syl
    Nov 29 '18 at 10:29






  • 1





    @Syl But the whole reason you've structured your route the way you have is because of the share functions. Ultimately that is the design decision that has caused this issue. This is essentially an XY Problem

    – Liam
    Nov 29 '18 at 10:32













  • What happen when I get null is that it solve the hash and return null because the second promise (invoice as a variable) should have been called inside the RSVP hash ?

    – Syl
    Nov 29 '18 at 10:41













  • if (model.invoice !== null) seems like the obvious solution

    – Liam
    Nov 29 '18 at 10:42








  • 1





    Or even just get your invoice call to return all the data you need in one go. Without multiple hops to the server. If allShares needs an invoice you could easily argue that it is part of invoice and should be loaded with it

    – Liam
    Nov 29 '18 at 10:46



















  • The share functions are not related to my problem, but thanks for the input. It is custom model function that are used to retrieve tabular data related to the model. I end up displaying them in tables.

    – Syl
    Nov 29 '18 at 10:29






  • 1





    @Syl But the whole reason you've structured your route the way you have is because of the share functions. Ultimately that is the design decision that has caused this issue. This is essentially an XY Problem

    – Liam
    Nov 29 '18 at 10:32













  • What happen when I get null is that it solve the hash and return null because the second promise (invoice as a variable) should have been called inside the RSVP hash ?

    – Syl
    Nov 29 '18 at 10:41













  • if (model.invoice !== null) seems like the obvious solution

    – Liam
    Nov 29 '18 at 10:42








  • 1





    Or even just get your invoice call to return all the data you need in one go. Without multiple hops to the server. If allShares needs an invoice you could easily argue that it is part of invoice and should be loaded with it

    – Liam
    Nov 29 '18 at 10:46

















The share functions are not related to my problem, but thanks for the input. It is custom model function that are used to retrieve tabular data related to the model. I end up displaying them in tables.

– Syl
Nov 29 '18 at 10:29





The share functions are not related to my problem, but thanks for the input. It is custom model function that are used to retrieve tabular data related to the model. I end up displaying them in tables.

– Syl
Nov 29 '18 at 10:29




1




1





@Syl But the whole reason you've structured your route the way you have is because of the share functions. Ultimately that is the design decision that has caused this issue. This is essentially an XY Problem

– Liam
Nov 29 '18 at 10:32







@Syl But the whole reason you've structured your route the way you have is because of the share functions. Ultimately that is the design decision that has caused this issue. This is essentially an XY Problem

– Liam
Nov 29 '18 at 10:32















What happen when I get null is that it solve the hash and return null because the second promise (invoice as a variable) should have been called inside the RSVP hash ?

– Syl
Nov 29 '18 at 10:41







What happen when I get null is that it solve the hash and return null because the second promise (invoice as a variable) should have been called inside the RSVP hash ?

– Syl
Nov 29 '18 at 10:41















if (model.invoice !== null) seems like the obvious solution

– Liam
Nov 29 '18 at 10:42







if (model.invoice !== null) seems like the obvious solution

– Liam
Nov 29 '18 at 10:42






1




1





Or even just get your invoice call to return all the data you need in one go. Without multiple hops to the server. If allShares needs an invoice you could easily argue that it is part of invoice and should be loaded with it

– Liam
Nov 29 '18 at 10:46





Or even just get your invoice call to return all the data you need in one go. Without multiple hops to the server. If allShares needs an invoice you could easily argue that it is part of invoice and should be loaded with it

– Liam
Nov 29 '18 at 10:46













2














First rule of helpers




Each time the input to a helper changes, the compute function will be called again.




Second, there's nothing about helpers that will make this block subsequent calls because you are returning a promise.



export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}


You've created a simple helper here that will use the promise itself as the value. Look at ember-promise-helpers/await to see how a class based helper is used to manually set the value that's displayed in the template.



Now, if you're wondering why the recomputation is happening, I'm going to have to speculate based off the knowledge I have of Ember data just from being part of the Ember community (I've never actually used Ember Data). You know line.pricing is a promise? I can then assume your using some sort of relationship, which will most likely have to be loaded via an ajax call (hence the promise). But these relationships in Ember data, iirc, use this PromiseProxyMixin that allow them to behave simultaneously like a promise or like an object (depending on whether the data is in the store already or not). This is what allows you to reference the promise in your template without then



See this article for a better understanding of what I mean






share|improve this answer



















  • 1





    I've never actually used Ember Data that is the best way to be. Worst part of Ember IMO

    – Liam
    Nov 29 '18 at 10:30











  • It wasn't 1.0 when I started Ember. Nowadays, I think ED has done a very good job solving this difficult problem in a general way. I just still find the benefit to complexity ratio heavily skewed in the direction of "do I really need a full fledged client side ORM?" I use semantically named services + my own relationship aware recursive deserializers/serializers + a promise returning wrapper "rest-client" that makes the http requests and knows how to communicate with my backend. Any new Ember dev that knows js groks the architecture without trying b/c its so explicit

    – mistahenry
    Nov 29 '18 at 10:40
















2














First rule of helpers




Each time the input to a helper changes, the compute function will be called again.




Second, there's nothing about helpers that will make this block subsequent calls because you are returning a promise.



export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}


You've created a simple helper here that will use the promise itself as the value. Look at ember-promise-helpers/await to see how a class based helper is used to manually set the value that's displayed in the template.



Now, if you're wondering why the recomputation is happening, I'm going to have to speculate based off the knowledge I have of Ember data just from being part of the Ember community (I've never actually used Ember Data). You know line.pricing is a promise? I can then assume your using some sort of relationship, which will most likely have to be loaded via an ajax call (hence the promise). But these relationships in Ember data, iirc, use this PromiseProxyMixin that allow them to behave simultaneously like a promise or like an object (depending on whether the data is in the store already or not). This is what allows you to reference the promise in your template without then



See this article for a better understanding of what I mean






share|improve this answer



















  • 1





    I've never actually used Ember Data that is the best way to be. Worst part of Ember IMO

    – Liam
    Nov 29 '18 at 10:30











  • It wasn't 1.0 when I started Ember. Nowadays, I think ED has done a very good job solving this difficult problem in a general way. I just still find the benefit to complexity ratio heavily skewed in the direction of "do I really need a full fledged client side ORM?" I use semantically named services + my own relationship aware recursive deserializers/serializers + a promise returning wrapper "rest-client" that makes the http requests and knows how to communicate with my backend. Any new Ember dev that knows js groks the architecture without trying b/c its so explicit

    – mistahenry
    Nov 29 '18 at 10:40














2












2








2







First rule of helpers




Each time the input to a helper changes, the compute function will be called again.




Second, there's nothing about helpers that will make this block subsequent calls because you are returning a promise.



export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}


You've created a simple helper here that will use the promise itself as the value. Look at ember-promise-helpers/await to see how a class based helper is used to manually set the value that's displayed in the template.



Now, if you're wondering why the recomputation is happening, I'm going to have to speculate based off the knowledge I have of Ember data just from being part of the Ember community (I've never actually used Ember Data). You know line.pricing is a promise? I can then assume your using some sort of relationship, which will most likely have to be loaded via an ajax call (hence the promise). But these relationships in Ember data, iirc, use this PromiseProxyMixin that allow them to behave simultaneously like a promise or like an object (depending on whether the data is in the store already or not). This is what allows you to reference the promise in your template without then



See this article for a better understanding of what I mean






share|improve this answer













First rule of helpers




Each time the input to a helper changes, the compute function will be called again.




Second, there's nothing about helpers that will make this block subsequent calls because you are returning a promise.



export function pricingsFullPricing([pricing]) {
return pricing.then(
p=>{
debugger
},p=>{

}
)
}


You've created a simple helper here that will use the promise itself as the value. Look at ember-promise-helpers/await to see how a class based helper is used to manually set the value that's displayed in the template.



Now, if you're wondering why the recomputation is happening, I'm going to have to speculate based off the knowledge I have of Ember data just from being part of the Ember community (I've never actually used Ember Data). You know line.pricing is a promise? I can then assume your using some sort of relationship, which will most likely have to be loaded via an ajax call (hence the promise). But these relationships in Ember data, iirc, use this PromiseProxyMixin that allow them to behave simultaneously like a promise or like an object (depending on whether the data is in the store already or not). This is what allows you to reference the promise in your template without then



See this article for a better understanding of what I mean







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 29 '18 at 10:29









mistahenrymistahenry

5,89431830




5,89431830








  • 1





    I've never actually used Ember Data that is the best way to be. Worst part of Ember IMO

    – Liam
    Nov 29 '18 at 10:30











  • It wasn't 1.0 when I started Ember. Nowadays, I think ED has done a very good job solving this difficult problem in a general way. I just still find the benefit to complexity ratio heavily skewed in the direction of "do I really need a full fledged client side ORM?" I use semantically named services + my own relationship aware recursive deserializers/serializers + a promise returning wrapper "rest-client" that makes the http requests and knows how to communicate with my backend. Any new Ember dev that knows js groks the architecture without trying b/c its so explicit

    – mistahenry
    Nov 29 '18 at 10:40














  • 1





    I've never actually used Ember Data that is the best way to be. Worst part of Ember IMO

    – Liam
    Nov 29 '18 at 10:30











  • It wasn't 1.0 when I started Ember. Nowadays, I think ED has done a very good job solving this difficult problem in a general way. I just still find the benefit to complexity ratio heavily skewed in the direction of "do I really need a full fledged client side ORM?" I use semantically named services + my own relationship aware recursive deserializers/serializers + a promise returning wrapper "rest-client" that makes the http requests and knows how to communicate with my backend. Any new Ember dev that knows js groks the architecture without trying b/c its so explicit

    – mistahenry
    Nov 29 '18 at 10:40








1




1





I've never actually used Ember Data that is the best way to be. Worst part of Ember IMO

– Liam
Nov 29 '18 at 10:30





I've never actually used Ember Data that is the best way to be. Worst part of Ember IMO

– Liam
Nov 29 '18 at 10:30













It wasn't 1.0 when I started Ember. Nowadays, I think ED has done a very good job solving this difficult problem in a general way. I just still find the benefit to complexity ratio heavily skewed in the direction of "do I really need a full fledged client side ORM?" I use semantically named services + my own relationship aware recursive deserializers/serializers + a promise returning wrapper "rest-client" that makes the http requests and knows how to communicate with my backend. Any new Ember dev that knows js groks the architecture without trying b/c its so explicit

– mistahenry
Nov 29 '18 at 10:40





It wasn't 1.0 when I started Ember. Nowadays, I think ED has done a very good job solving this difficult problem in a general way. I just still find the benefit to complexity ratio heavily skewed in the direction of "do I really need a full fledged client side ORM?" I use semantically named services + my own relationship aware recursive deserializers/serializers + a promise returning wrapper "rest-client" that makes the http requests and knows how to communicate with my backend. Any new Ember dev that knows js groks the architecture without trying b/c its so explicit

– mistahenry
Nov 29 '18 at 10:40


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526134%2fthen-returning-a-null-value-when-it-should-be-pending%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)