Created
December 22, 2015 11:52
-
-
Save me-andre/0ca8b80239cd4624e6fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FluxCache store={store} propName="items" component={Component} id={this.props.routeParams.id} /> | |
var FluxCache = React.createClass({ | |
componentWillMount() { | |
this.props.store.addListener('change', this.onStoreChange); | |
}, | |
componentWillUnmount() { | |
this.props.store.removeListener('change', this.onStoreChange); | |
}, | |
onStoreChange() { | |
this.setState({data: this.props.store.read()}); | |
}, | |
render() { | |
var Component = this.props.component; | |
var props = omit(this.props, 'propName'); | |
props[this.props.propName] = this.state.data; | |
return <Component {...props} />; | |
} | |
}); | |
var Component = React.createClass({ | |
render() { | |
var item = this.props.items[this.props.id]; | |
return <div>{item.name}</div>; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment