-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e48029
commit 4a34609
Showing
3 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const React = require('react-native'); | ||
const { | ||
View, | ||
} = React; | ||
const PostDetail = require('./components/PostDetail'); | ||
|
||
const _ = require('underscore'); | ||
|
||
const helpers = require('./helpers.js'); | ||
const { LoadingView } = helpers; | ||
|
||
const store = require('./store'); | ||
|
||
const styles = {}; | ||
|
||
const PostDetailLoader = React.createClass({ | ||
propTypes: { | ||
slug: React.PropTypes.string.isRequired, | ||
}, | ||
|
||
getInitialState: function() { | ||
return { | ||
post: undefined, | ||
loaded: false, | ||
}; | ||
}, | ||
|
||
componentDidMount: function() { | ||
this.cursor = store.select('models', 'posts', this.props.slug); | ||
this.cursor.on('update', this.updateState); | ||
this.updateState(); | ||
}, | ||
|
||
updateState: function() { | ||
const post = this.cursor.get(); | ||
if (!_.isUndefined(post)) { | ||
this.setState({ | ||
post, | ||
loaded: true, | ||
}); | ||
} | ||
}, | ||
|
||
renderLoadingView: function() { | ||
return ( | ||
<View style={styles.container}> | ||
<LoadingView /> | ||
</View> | ||
); | ||
}, | ||
|
||
render: function() { | ||
if (!this.state.loaded) { | ||
return this.renderLoadingView(); | ||
} | ||
return ( | ||
<PostDetail post={this.state.post} /> | ||
); | ||
}, | ||
}); | ||
|
||
module.exports = PostDetailLoader; |
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