fluxo-js / fluxo

Fluxo is a simple, lightweight (~300LOC) and dependency free data infrastructure lib based on Facebook Flux and Backbone.js. It's compatible with React.js, but you can use with whatever you want to the view/component layer.
15 stars 3 forks source link

Collection store not sorting when update a children store #27

Closed samuelsimoes closed 8 years ago

samuelsimoes commented 8 years ago

When the attribute used to sort the collection store is changed on some children store the collection store doesn't reorder itself.

sobrinho commented 8 years ago

Yes, makes sense.

The current implementation is very rudimentar, just the basic sort.

Are you thinking in listen the change:$attribute to reorder?

sobrinho commented 8 years ago

I vaguely remember that add stores, reset and etc wasn't resorting either.

samuelsimoes commented 8 years ago

Today only the add method reorders the collection. About your suggestion to listen to the attribute to make the ordering I agree, but what API we would use?

Something like this below?

class Foo extends CollectionStore {
  static sort = {
    on: ["stores:change:name"],
    resolve: ((a, b) => a.data.order - b.data.order)
  };
}
sobrinho commented 8 years ago

Can't we just call the order method again (just like backbone)?

This means we would listen to change instead of change:attr.

Performance would be worse but until someone is using thousands of stores, we may not need to worry.

samuelsimoes commented 8 years ago

Ok. Listening to the collection change could the job. 👌 I will submit a patch soon.