0
votes

I have two related models, an Order which contains several Payments.

Order also has a total property. Each Payment is a percentage of the total. Therefore, when total changes, each payment observes it and calculates its partial total.

My problem arises from the fact that Order has also an Ember.computed.sum of those totals, in case the percentages are not yet 100%.

Ember.js issues an "Assertion Failed: You modified computedTotal twice on <iec-jbe@component:order-form::ember906> in a single render. This was unreliable and slow in Ember 1.x and is no longer supported. See https://github.com/emberjs/ember.js/issues/13948 for more details.".

I understand why this happens, but I can't see a better way to do what I need to do. Can anyone help me here?

2
Please show your computed prop. Anyway I think there is a problem which could be solved with emberjs.com/api/classes/Ember.run.html#method_once - Ebrahim Pasbani
Thank you, this solved it for me. It may not be the most elegant way, but it saved me a lot of refactoring - delCano
Sorry, I added it now. - delCano
Great, thanks. Also, if you want to attract someone's attention, please use their name (like @halfer, tab completion is available). I don't have to here though since this is your post, and you get all notifications. - halfer

2 Answers

2
votes

I think you should refactor, that you don't use observers. Just use a computed property for total, and do your logic in the setter.

1
votes

I solved it using Ember.run.once as suggested by Ebrahim Pasbani in a comment, and further developped here: Observers.

This may not be the best solution, but due to the very advanced state of our project, refactoring so to use computed properties instead of one observer would have meant so many changes it wasn't worth it. I say this to make clear this is not the best solution for most cases, it just the best solution in this particular case.