Created
October 22, 2015 22:04
-
-
Save fuermosi777/99a06244f3fdf3ef83f2 to your computer and use it in GitHub Desktop.
A Flux-like structure for React Native
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
... | |
render() { | |
return ( | |
<View> | |
// two components | |
<ListView/> | |
<MapView/> | |
</View> | |
) | |
} | |
... |
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
module.exports = { | |
clickItem() { | |
return fetch(url) | |
.then(res => res.json()) | |
.then((data) => { | |
return ContentStores.setItem(data); | |
}); | |
} | |
} |
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
module.exports = { | |
setItem(data: Array) { | |
return AsyncStorage.setItem('item', JSON.stringify(item)) | |
.then((res) => { | |
PubSub.publish('ITEM_CLICKED') | |
}); | |
} | |
} |
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
... | |
handleItemPress() { | |
ContentActions.clickItem(); | |
} | |
... |
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
... | |
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