Assume this example:
obs1: function() {
var prop1 = this.get('prop1');
// Some ajax request
}.observes('prop2'),
prop1: function() {
var prop2 = this.get('prop2');
return prop2 + 1;
}.property('prop2'),
What can happen if prop2 is changed is that obs1 is called before prop1 and hence I will not have actual value of prop1 in obs1 during first call of obs1. I can do wrong ajax request in obs1 which adds overhead to my application or I can run into exception because of outdated value of prop1.
Adding prop1 in observes(...) does not help.
How is the call order determined when more than one method (either property or observer) waits in call buffer? How can I enforce computation of all properties before first observer is called? Am I doomed to compute prop1 in obs1 on my own (trying to avoid call to prop1)?
$ ember -v
version: 0.1.15
node: 0.12.0
npm: 2.1.8
Continuing...
There are many errors that can arise because calling order is not properly defined. Imagine (I will omit the code sample) you are working with an array and an index. In some method you access an item of this array using index. If (because of calling order) array has been updated but index hasn't been updated, then you can run into index out of range exception.
Aucun commentaire:
Enregistrer un commentaire