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

React's "propTypes" like #26

Closed samuelsimoes closed 8 years ago

samuelsimoes commented 8 years ago

Today, without default attributes I can't easily find what attributes a store needs/uses. To address this issue, ReactJS has the propTypes key on the components. It's very useful because on a glance I can recognize all component's attributes dependencies.

What do you think about this on Fluxo?

samuelsimoes commented 8 years ago

Some conversation about this also on https://github.com/fluxo-js/fluxo/issues/20#issuecomment-182044996.

sobrinho commented 8 years ago

Would be nice :shipit:

samuelsimoes commented 8 years ago

So, summarizing the ideas of the other issue (#20) this would be like this:

class Person extends Fluxo.ObjectStore {
  static attributes = {
    author: {
      defaultValue: {},
      required: true,
      parser: function (value) { return new Fluxo.ObjectStore(value); },
      dump: function (value) { return value.data.id; }
    }
    age: { 
      defaultValue: 0,
      required: true,
      parser: function (value) { return parseInt(value, 10); }
    },
    name: { required: true }
  };
}

Are you ok with this, @sobrinho?

samuelsimoes commented 8 years ago

The required there is only a hint, not a validation (like Backbone, for example).

samuelsimoes commented 8 years ago

PR included.