helper functions and decorators for purification of react components with global dependencies and context. Simplifies the implementation of a flux-architecture
npm install react-purifyThis handy ES7 decorators makes it easy to implement (or migrate gradually)
your react-components to a flux-like architecture.
Goal of this library is empowering users to purify components quickly without breaking existing architectures.
``js
import {pure,mix} form 'react-purify'
@pure() // pureRenderMixin
class MyPureComponent extends React.Component {
//...
}
//if you need more mixins :
@mix([LinkedStateMixin,PureRenderMixins,...])
class MyComp {
//...
}
`
`js
import {UI,pureUI} form 'react-purify'
const MyPureComponent = pureUI( p=> (
`
`js
var appState={todo:[/.../]};
import {inject,use} form 'react-purify'
@inject({appState}) // or @inject({appState:appState})
class TodoApp {
render(){
return
}
}
@use( // transfers context to props
['appState'], //get the appState
p=>({ //extract component dependencies
todo:p.appState.todo
})
)
@pure() // lets only redraw if todos have changed
class TodoList {
render(){
return
//The example above shows how you can gradually move dependencies. Following code is equivallent :
@inject({appState})
@use(['appState'],p=>(
{todo:p.appState.todo})
)
class TodoApp {
render(){
return
}
}
@pure()
class TodoList {
render(){
return
``