I'm currently observing some Ember arrays like so:
observe_array: function() {
this.get("my_array").forEach(function(e,i) {
// do something
});
}.observes("my_array.@each");
Most times, if my_array is updated, multiple elements are added at once. However, the observer fires one-by-one as each element is added, which becomes extremely inefficient. Is there anyway to do this more efficiently? Essentially, I need to be able to have a mutated array based on "my_array"
For reference, realistic sizes of my_array will be between 600-1200 elements. The "do something" block involves some operations that take a little more time - creating Date objects from strings and converting each element to json representation.
Instead of doing an observer I also tried a property with the cacheable() method/flag, but that didn't seam to speed things up very much....
Assuming (via comments) that your array is an ember-data populated one, you should try observing array.isUpdating
property. I got success w/ this one.
The only drawback is it is only set when using .findAll()
! (so Model.find()
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With