Skip to content
This repository has been archived by the owner. It is now read-only.
Composables for React.
Branch: master
Clone or download
Latest commit a9d66eb Jun 20, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist Rebuild dist Oct 25, 2016
docs Rtype sig fix Dec 22, 2015
src renamed isDesc to isStampDescriptor Oct 25, 2016
test renamed isDesc to isStampDescriptor Oct 25, 2016
.babelrc Use .babelrc Dec 26, 2015
.editorconfig Initial implementation Sep 27, 2015
.eslintrc Fix Travis Oct 25, 2016
.gitignore Initial implementation Sep 27, 2015
.travis.yml Update .travis.yml Nov 16, 2016
README.md Update README.md Jun 20, 2019
package.json chore(package): update dependencies Nov 16, 2016
webpack.config.js Use .babelrc Dec 26, 2015

README.md

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 😞).

Examples

Docs

You can’t perform that action at this time.