Home

Awesome

react-stamp build statusGreenkeeper Badge npm version license

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

Status - DEPRECATED

Try React hooks or compose components with higher-order components and function composition, instead.

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