0

Currently I have controller field that contains Mutable Array full of objects. Each time i add/remove elements in array - template rendering occurs. That is good.

And now i have a situation, where I have to replace whole array.

If I do this via .clear() and then .pushObjects() I see template flickering.

It is pretty noticeable, because Em render empty template at .clear and render template again, after .pushObjects() call.

I thought, is there any way to pause template rendering while model is updating? In this case should be only one render call, and flickering shouldn't be.

So question is: how to control rendering process in Ember?

2 Answers 2

0

Ember will update your template when you call the set method. For example, in one of your controller functions, you may do something like this:

var someArray = [ 1, 2, 3, 4, 5 ];
this.set('myArray', someArray);

This will cause anything binding to myArray to update. In your case, I would get your array, do your modifications (clear and pushObjects), then call set:

var arr = this.get('myArray');
arr.clear();
arr.pushObjects(...);
this.set('myArray', arr);
Sign up to request clarification or add additional context in comments.

4 Comments

I think when you get reference to myArray and do .clear and .pushObjects will cause re-rendering each time because observers still attached to mutable array.
Can you look at this jsbin and let me know how yours differs?
I understood you, in this solution you don't see flickering because you just don't have much html over there. If you have complicated template - you definitely will see laggs.
It's more likely that you observe binding/rendering big bulk of data problem (which is pain in Ember) than anything else. I'd recommend to consider use of CloakedView or Ember.ListView for your case.
0

Ember uses run loop and queues to avoid described problem. Do you change the array (clean & fulfill) in a synchronous way?

1 Comment

var controller = App.__container__.lookup('controller:MyController'); var options = controller.get('options'); options.clear(); var objects = [{ //obj1 }, { //obj2 }, { //obj3 }]; options.pushObjects(objects); I need update model from outside of ember framework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.