backbone-redux icon indicating copy to clipboard operation
backbone-redux copied to clipboard

Try to save the order of entities when merging new models

Open somebody32 opened this issue 9 years ago • 1 comments

Now on every update changed models are removed from the entities array and updated ones are added to the end of it. This forces user to do a sorting by id (or any other field in the view layer). It will be great to preserve the initial order of the models on an update.

Ie, this code should pass:

const testSaveOrder = () => {
  const initialStore = [
    {id: 1, name: 'lol'},
    {id: 2, name: 'lol2'},
    {id: 3, name: 'lol3'},
  ];

  const newStore = mergeStore(
    initialStore, 
    [
      {id: 2, name: 'lol22'},
      {id: 4, name: 'lol4'}
    ]
  );

  expect(newStore).toEqual([
    {id: 1, name: 'lol'},
    {id: 2, name: 'lol22'},
    {id: 3, name: 'lol3'},
    {id: 4, name: 'lol4'}
  ]);
};

testSaveOrder();

somebody32 avatar Feb 10 '16 18:02 somebody32

Shouldn't it simply follow the order as described by the comparator function in the Backbone collection?

Robinfr avatar Apr 29 '16 08:04 Robinfr