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

Removing "data" key on collection's toJSON #15

Closed samuelsimoes closed 9 years ago

samuelsimoes commented 9 years ago

A collection usually doesn't have too many attributes, generally it has just some computed properties (and subsets soon). Today, the collection's toJSON exports the collection's store data on data key and stores data on stores key.

This create a useless difference between a single store toJSON, that just export the data without any "padding key", and a collection store toJSON. This was a initial decision to avoid toJSON attributes clash, but collections having a few attributes and it being a problem only if developer use store and subsets name as collection store's attributes I think is reasonable remove the data key on collection's toJSON.

sobrinho commented 9 years ago

Makes sense to remove to keep parity.

Would be interesting to see an error when to try define an attribute with name as a subset, example:

class Collection extends Fluxo.Collection {
  static subset = {
    online: ["stores:change:online"]
  };

  online () {
    return this.where({online: true});
  }
}

var c = new Collection;
c.setAttribute("stores", true); // => You can't use stores as attribute, there is a subset using that name
c.setAttribute("online", true); // => You can't use online as attribute, there is a subset using that name

Makes sense?

samuelsimoes commented 9 years ago

I totally agree! Lets first merge the subset feature and then we make this change and create the errors. :ok_hand: