stampit-org / react-stampit

A specialized stampit factory for React
131 stars 1 forks source link

Strip state prop in favor of init? #31

Closed troutowicz closed 9 years ago

troutowicz commented 9 years ago

It has been mentioned a few times now how an init method prop in the description object would be useful. See issues #21, #29. What if the API was changed, removing the state prop of the description object and in it's place have more flexible init method prop?

init would behave just as init behaves in the core stampit library, so component state would be set like:

stampit(React, {
  init() {
    this.state = { ... }
  }
});

instead of

stampit(React, {
  state: { ... }
});

This is more typing for declaring component state, but the init method would allow a wide range of use cases currently not possible. It also makes sense to have a constructor like method at the stamp level (init) as well as the React level (componentWillMount).

BerkeleyTrue commented 9 years ago

Why not both? That way it's just a minor version bump instead of a breaking change.

troutowicz commented 9 years ago

Yeah that's a better idea. :)

BerkeleyTrue commented 9 years ago

:+1: for that!

ericelliott commented 9 years ago

Why not add .compose() and initializers seeing as how we need to get moving toward the open Stamp specification anyway?

IMO, the best thing about the stamp specification is that all the stampit idioms will still work, and we get full control of the stamp API so that it's a breeze to offer the React-specific stuff.

ericelliott commented 9 years ago

Also, :+1: for doing both, not stripping state.