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