Skip to content

Instantly share code, notes, and snippets.

@lhahne
Last active August 29, 2015 14:21
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 lhahne/8d0d038a7d3fd65fcde4 to your computer and use it in GitHub Desktop.
Save lhahne/8d0d038a7d3fd65fcde4 to your computer and use it in GitHub Desktop.
react native view
var React = require('react-native')
var {Text, ListView, AppRegistry} = React
var StationMetadataStore = require('./StationMetadataStore')
var StationList = React.createClass({
getInitialState() {
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
return {stations: ds.cloneWithRows([])}
},
componentDidMount() {
this.unsubscribe =
StationMetadataStore.stationsByCode.onValue(stationCodes => {
this.setState({
stations: this.state.stations.cloneWithRows(stationCodes)
})
})
},
componentWillUnmount() {
this.unsubscribe()
},
render() {
return <ListView
dataSource={this.state.stations}
renderRow={(rowData) => <Text>{rowData.stationShortCode}: {rowData.stationName}</Text>}
pageSize="20" />
}
})
AppRegistry.registerComponent('StationList', () => StationList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment