forked from grigio/flow-router-react-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.jsx
59 lines (50 loc) · 1.36 KB
/
page.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
if (Meteor.isClient) {
Page = React.createClass({
mixins: [ DDPMixin, ReactiveMixin ],
getReactiveState: function() {
return {
postContent: this.getPostContent(),
categories: this.getCategories(),
comments: this.getComments()
}
},
getPostContent:function () {
if (FlowRouter.subsReady('currentPost'))
return "This is a very cool blog post"
else
return "loading post.."
},
getCategories: function() {
// render categories after all subscriptions are ready
if (FlowRouter.subsReady()) {
var categories = Categories.find().fetch();
return _.pluck(categories, 'text').join(', ');
}
},
getComments:function () {
// Render comments as they came
return Comments.find();
},
renderComment: function(model) {
return (
<p key={model._id}>{model.text}</p>
)
},
render: function() {
return (
<div className="page">
<h1>My Blog</h1>
{this.state.postContent}
<div className="categories">
<h3>Categories</h3>
Categories: {this.state.categories}
</div>
<div className="comments">
<h4>Comments</h4>
{this.state.comments.map(this.renderComment)}
</div>
</div>
)
}
});
}