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

Default values #9

Closed sobrinho closed 9 years ago

sobrinho commented 9 years ago

Would be nice to have default values like this:

MyStore = Fluxo.CollectionStore.extend({
  defaults: {
    someFilter: true,
    anotherFilter: {}
  }
});

Note that in store constructor we need to deep clone the defaults to avoid mutating the defaults object itself.

Backbone did a different approach which I don't like (isn't obvious that it need to be that way until you find a obscure bug):

MyModel = Backbone.Model.extend({
  defaults: function () {
    return {
      someFilter: true,
      anotherFilter: {}
    };
  }
});

Although using function is a must because we may need to use new Date() for example:

MyStore = Fluxo.CollectionStore.extend({
  defaults: function () {
    return {
      someFilter: new Date,
      anotherFilter: {}
    };
  }
});

Using classes it would be a static property:

class MyStore extends Fluxo.CollectionStore {
}

MyStore.defaults = { ... };
samuelsimoes commented 9 years ago

:ok_hand:

sobrinho commented 9 years ago

See #11