Ember itemController gets reinstantiated when ArrayController reorders

Andrew

Is this expected behavior?

App.PostsController = Ember.ArrayController.extend({
  itemController: 'post',
  sortProperties: ['date'],
  sortAscending: false
});

App.PostController = Ember.ObjectController.extend({
  init: function () {
    console.log('post controller init');
    this.set('propertyNotIncludedInModel', true);
  }
});

Say I have a list of posts, and I inline-edit one of the post's date. The PostsController will reorder the list. As soon as it does, the console will log that the one whose date changed ran init. Of course, any controller properties (not model properties), are no longer there (I mean, it's a new object, so any property that doesn't have a reason to be there is undefined).

You can see this happening in this jsBin.

This seems horribly wrong. I feel like it breaks any sort of analogy to real life. If I have a bunch of objects sitting on a table and I want to reorder them, I don't destroy the one I want to move and then recreate it. What is Ember's justification for this behavior, and how do I deal with it? I need to set controller properties on an object whose position in an array might change. Even better, I need the views and their components represented by that object to persist and maintain their own states and properties as well—currently didInsertElement is being called on every view/component under the item controller, messing things up more. How do I make sure the properties and subviews I need persist when the object gets moved?

Aaron Renoir

Its up to you how you apply changes to state. If you are ordering by a property the order will change as soon as the property changes. If you want to wait for something to happen before triggering the reorder I would use the buffered proxy pattern. I edited your jsbin as an example. http://jsbin.com/zopelu/1/

EDIT I missed the part about the controller being destroyed and recreated. I think that bug was introduced in 1.7 and almost fixed

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ember itemController gets reinstantiated when ArrayController reorders

From Dev

In Ember.js how to notify an ArrayController's corresponding itemController, when a property on the ArrayController changes

From Dev

How to define a Ember.computed helper that acts on the itemController of a Ember.ArrayController?

From Dev

Removing an itemController when upgrading to Ember 2.0

From Dev

How to access ItemController from ArrayController

From Dev

Setting itemController on a filtered subset of an ArrayController's model

From Dev

Mutual Exclusion in an Ember ArrayController

From Dev

Ember Controller vs Ember ArrayController

From Dev

Can I have a custom View when using itemController in Ember.js?

From Dev

Ember.js ArrayController error

From Dev

Ember.js ArrayController error

From Dev

Ember.js: Reference index in itemController

From Dev

Ember.js: Grouping/partitioning an ArrayController

From Dev

Accessing clicked model in an Ember.ArrayController

From Dev

Moving an ArrayController/View to a Component in Ember 1.13

From Dev

Ember.js cannot set content of ArrayController

From Dev

Why are my Ember.ArrayController itemControllers undefined?

From Dev

How to sort an ArrayController backed by Ember-Model?

From Dev

Ember.js: Grouping/partitioning an ArrayController

From Dev

ember.js using itemController with each helper doesnt work as expected

From Dev

How to set itemController in each as (ember 1.11 beta3)?

From Dev

What is the reference for this Ember.js guides setupController multiple models with arraycontroller

From Dev

How do I fetch a collection of objects using Ember ArrayController?

From Dev

Ember.js: Deleting an Item from a Sorted ArrayController

From Dev

ember js how to push object to the top of the stack in the ArrayController

From Dev

How to display filtered ArrayController content in Ember.js

From Dev

Ember.js: Adding item to an ArrayController without creating it first?

From Dev

ember js how to push object to the top of the stack in the ArrayController

From Dev

Can't clear an ArrayController when sortProperties is set

Related Related

  1. 1

    Ember itemController gets reinstantiated when ArrayController reorders

  2. 2

    In Ember.js how to notify an ArrayController's corresponding itemController, when a property on the ArrayController changes

  3. 3

    How to define a Ember.computed helper that acts on the itemController of a Ember.ArrayController?

  4. 4

    Removing an itemController when upgrading to Ember 2.0

  5. 5

    How to access ItemController from ArrayController

  6. 6

    Setting itemController on a filtered subset of an ArrayController's model

  7. 7

    Mutual Exclusion in an Ember ArrayController

  8. 8

    Ember Controller vs Ember ArrayController

  9. 9

    Can I have a custom View when using itemController in Ember.js?

  10. 10

    Ember.js ArrayController error

  11. 11

    Ember.js ArrayController error

  12. 12

    Ember.js: Reference index in itemController

  13. 13

    Ember.js: Grouping/partitioning an ArrayController

  14. 14

    Accessing clicked model in an Ember.ArrayController

  15. 15

    Moving an ArrayController/View to a Component in Ember 1.13

  16. 16

    Ember.js cannot set content of ArrayController

  17. 17

    Why are my Ember.ArrayController itemControllers undefined?

  18. 18

    How to sort an ArrayController backed by Ember-Model?

  19. 19

    Ember.js: Grouping/partitioning an ArrayController

  20. 20

    ember.js using itemController with each helper doesnt work as expected

  21. 21

    How to set itemController in each as (ember 1.11 beta3)?

  22. 22

    What is the reference for this Ember.js guides setupController multiple models with arraycontroller

  23. 23

    How do I fetch a collection of objects using Ember ArrayController?

  24. 24

    Ember.js: Deleting an Item from a Sorted ArrayController

  25. 25

    ember js how to push object to the top of the stack in the ArrayController

  26. 26

    How to display filtered ArrayController content in Ember.js

  27. 27

    Ember.js: Adding item to an ArrayController without creating it first?

  28. 28

    ember js how to push object to the top of the stack in the ArrayController

  29. 29

    Can't clear an ArrayController when sortProperties is set

HotTag

Archive