react-stamp

Composables for React.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
react-stamp
0.6.06 years ago7 years agoMinified + gzip package size for react-stamp in KB

Readme

build status npm version license
react-stamp
Composables for React.

react-stamp has replaced react-stampit and is compliant with the stamp specification. The Rtype specification is used for documenting function signatures and data structures.
npm install react-stamp --save

What is composition?

Composition is the act of creating an object from a collection of other objects. Many will say this is actually multiple inheritance, not composition. Well, in the classical sense of the word, they're right! However, JavaScript favors prototypal inheritance, and composition is actually Prototypal OO's primary mechanism. Composition encompasses differential inheritance, concatenative inheritance, and functional inheritance.

But I like HOCs.

So do I! HOC factories provide a functional API for component composition and stamp composition can be a nice complement. If the goal is to be functional and avoid APIs that expose class and it's pseudo-classical behavior, why use class at all?

React.createClass 2.0?

No. The only similarity is that both provide forms of object composition. react-stamp decouples the relationship between component and mixin while being less opinionated. This provides greater flexibility.

So what is this?

react-stamp is the result of wondering about what other ways a React component could be represented. Stamps are a cool concept and more importantly have proven to be a great alternative to React.createClass and the ES2015 class due to their composability.
react-stamp exports a function that accepts one parameter, the React library.
reactStamp(React?: Object) => Stamp

This method converts React's Component constructor function into a stamp. To create a React component, we pass a descriptor object to the stamp's compose method.
interface ReactDesc {
  displayName?: String,
  init?: Function,
  state?: Object,
  statics?: Object,
  contextTypes?: Object,
  childContextTypes?: Object,
  propTypes?: Object,
  defaultProps?: Object,
  ...methods?: Function
}

stamp.compose(...desc?: Stamp|ReactDesc|SpecDesc[]) => Stamp

The most powerful feature of stamps is their composability. Any number of stamps can be combined into a new stamp which inherits each passed stamp's behavior. This behavior is suitable for React since class is being pushed as the new norm and does not provide an idiomatic way to utilize mixins. (classical inheritance :disappointed:).

Examples

Docs