Skip to content

Commit dac3117

Browse files
committed
ported the flow-router demo to React
1 parent 523a3ae commit dac3117

File tree

4 files changed

+71
-49
lines changed

4 files changed

+71
-49
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## Subscriptions Management with Flow Router
1+
## Subscriptions Management with Flow Router and React
2+
3+
with `grigio:babel` + `grove:react`
24

35
See:
46

ccd.html

+7-29
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
<template name="page">
2-
<div class="page">
3-
<h1>My Blog</h1>
4-
<div class="post">
5-
{{#if isReady "currentPost"}}
6-
<!-- render the blog post -->
7-
This is a very cool blog post
8-
{{else}}
9-
Loading...
10-
{{/if}}
11-
</div>
12-
<div class="categories">
13-
<h3> Categories </h3>
14-
{{#if isReady}}
15-
<!-- render categories after all subscriptions are ready -->
16-
Categories: {{getCategories}}
17-
{{/if}}
18-
<!-- No need to show some loading message -->
19-
</div>
20-
</div>
21-
22-
<div class="comments">
23-
<!-- Render comments as they came -->
24-
<h4>Comments</h4>
25-
{{#each getComments}}
26-
<div>{{text}}</div>
27-
{{/each}}
28-
</div>
29-
</template>
1+
<head>
2+
<title></title>
3+
</head>
4+
<body>
5+
<!-- This will be filled by FlowRouter with React stuff -->
6+
<div id="yield"></div>
7+
</body>

ccd.js renamed to ccd.jsx

+2-19
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,8 @@ if (Meteor.isClient) {
99
},
1010

1111
action: function() {
12-
// We render the template with Flow Layout
13-
FlowLayout.render('page');
14-
}
15-
});
16-
17-
Template.page.helpers({
18-
isReady: function(sub) {
19-
if(sub) {
20-
return FlowRouter.subsReady(sub);
21-
} else {
22-
return FlowRouter.subsReady();
23-
}
24-
},
25-
getComments: function() {
26-
return Comments.find();
27-
},
28-
getCategories: function() {
29-
var categories = Categories.find().fetch();
30-
return _.pluck(categories, 'text').join(', ');
12+
// We render the template with React
13+
React.render(<Page />, document.getElementById('yield'));
3114
}
3215
});
3316
}

page.jsx

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

0 commit comments

Comments
 (0)