Bug or Feature? (run loop, render engine)


#1

Hello,

we have an array of ember objects which we render in a template with the component helper as follows:

{{each objects as |obj|}}
   {{component obj.name}}
{{/each}}

Now as we replace the array with another one that contains new objects and some of the old ones - the components which had underlying old objects are never destroyed, they show in the right order instead. Ember somehow figures out that the components render the same object and doesn’t destroy them. Is that an expected behaviour?

Example:

Functions:

renderInitialObjects: ->
   objects = [ Obj1, Obj2, Obj3]
   @set 'objects', objects

stateChanged: ->

  objects  = [Obj4, Obj5, Obj1] //New Array
  @set 'objects', objects

In this case on ‘stateChanged’ Ember wouldn’t render a new component with underlying Obj1, but will use the old one instead.

GitHub Issue: https://github.com/emberjs/ember.js/issues/12683


#2

As was replied on the github issue you linked, it is the intended behavior. Ember does examine the list of already rendered stuff and reuses the ones it can reuse, for performance.

The question is, why would this surprise you? Were you trying to accomplish something specific that depended on another behavior?