nervnode
v0.4.1
Published
解决组件间通信问题
Downloads
31
Readme
nervnode 是什么
解决 React-like 框架中 Component 之间的通信问题,提供异于 Redux 的跨组件通信的解决方案
nervnode 支持的 React-like 库
- [v] Inferno
- [v] React
- [x] Preact
安装
npm install nernode --save
yarn add nervnode
用法
const Component from inject
const { insertNerv } from 'nervnode'
class Ping extends Component {
constructor(props) {
super(props)
this.state = { message: '' }
}
componentDidMount() {
// 此组件加载完成后即可发送相应的 Message
this.props.pong()
}
componentWillReceiveProps(nextProps) {
this.setState({ message: nextProps.message })
}
render() {
return <div />
}
}
const listenFunc = (setProps, localContext) {
return {
'ping': (msg) => setProps({ message: msg.message })
}
}
const dispatchFunc = (dispatch, localContext) {
return {
pong: () => dispatch('pong', {})
}
}
const filter = {
in: ['*'],
out: ['*'],
}
const PintNerv = insertNerv(listenFunc, dispatchFunc, filter)(Ping)