Skip to content

Instantly share code, notes, and snippets.

@fuermosi777
Created October 22, 2015 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuermosi777/99a06244f3fdf3ef83f2 to your computer and use it in GitHub Desktop.
Save fuermosi777/99a06244f3fdf3ef83f2 to your computer and use it in GitHub Desktop.
A Flux-like structure for React Native
...
render() {
return (
<View>
// two components
<ListView/>
<MapView/>
</View>
)
}
...
module.exports = {
clickItem() {
return fetch(url)
.then(res => res.json())
.then((data) => {
return ContentStores.setItem(data);
});
}
}
module.exports = {
setItem(data: Array) {
return AsyncStorage.setItem('item', JSON.stringify(item))
.then((res) => {
PubSub.publish('ITEM_CLICKED')
});
}
}
...
handleItemPress() {
ContentActions.clickItem();
}
...
...
ComponentDidMount() {
PubSub.subscribe('ITEM_CLICKED', this.handleItemClicked);
},
ComponentWillUnmount() {
PubSub.unsubscribe('ITEM_CLICKED', this.handleItemClicked);
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment