3
3
* All rights reserved.
4
4
*
5
5
* This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
7
* of patent rights can be found in the PATENTS file in the same directory.
8
8
*/
9
9
10
- var CommentsBox = React . createClass ( {
11
- propTypes : {
12
- initialComments : React . PropTypes . array . isRequired ,
13
- commentsPerPage : React . PropTypes . number . isRequired
14
- } ,
15
- getInitialState : function ( ) {
16
- return {
17
- comments : this . props . initialComments ,
18
- page : 1 ,
19
- hasMore : true ,
20
- loadingMore : false
21
- } ;
22
- } ,
23
- loadMoreClicked : function ( evt ) {
10
+
11
+ class CommentsBox extends React . Component {
12
+ static propTypes = {
13
+ initialComments : PropTypes . array . isRequired ,
14
+ commentsPerPage : PropTypes . number . isRequired
15
+ } ;
16
+
17
+ state = {
18
+ comments : this . props . initialComments ,
19
+ page : 1 ,
20
+ hasMore : true ,
21
+ loadingMore : false
22
+ } ;
23
+
24
+ loadMoreClicked = ( evt ) => {
24
25
var nextPage = this . state . page + 1 ;
25
26
this . setState ( {
26
27
page : nextPage ,
@@ -40,8 +41,9 @@ var CommentsBox = React.createClass({
40
41
} . bind ( this ) ;
41
42
xhr . send ( ) ;
42
43
evt . preventDefault ( ) ;
43
- } ,
44
- render : function ( ) {
44
+ } ;
45
+
46
+ render ( ) {
45
47
var commentNodes = this . state . comments . map ( function ( comment ) {
46
48
return < Comment author = { comment . Author } > { comment . Text } </ Comment > ;
47
49
} ) ;
@@ -55,8 +57,9 @@ var CommentsBox = React.createClass({
55
57
{ this . renderMoreLink ( ) }
56
58
</ div >
57
59
) ;
58
- } ,
59
- renderMoreLink : function ( ) {
60
+ }
61
+
62
+ renderMoreLink = ( ) => {
60
63
if ( this . state . loadingMore ) {
61
64
return < em > Loading...</ em > ;
62
65
} else if ( this . state . hasMore ) {
@@ -68,14 +71,15 @@ var CommentsBox = React.createClass({
68
71
} else {
69
72
return < em > No more comments</ em > ;
70
73
}
71
- }
72
- } ) ;
74
+ } ;
75
+ }
76
+
77
+ class Comment extends React . Component {
78
+ static propTypes = {
79
+ author : PropTypes . object . isRequired
80
+ } ;
73
81
74
- var Comment = React . createClass ( {
75
- propTypes : {
76
- author : React . PropTypes . object . isRequired
77
- } ,
78
- render : function ( ) {
82
+ render ( ) {
79
83
return (
80
84
< li >
81
85
< Avatar author = { this . props . author } />
@@ -84,13 +88,14 @@ var Comment = React.createClass({
84
88
</ li >
85
89
) ;
86
90
}
87
- } ) ;
91
+ }
92
+
93
+ class Avatar extends React . Component {
94
+ static propTypes = {
95
+ author : PropTypes . object . isRequired
96
+ } ;
88
97
89
- var Avatar = React . createClass ( {
90
- propTypes : {
91
- author : React . PropTypes . object . isRequired
92
- } ,
93
- render : function ( ) {
98
+ render ( ) {
94
99
return (
95
100
< img
96
101
src = { this . getPhotoUrl ( this . props . author ) }
@@ -100,8 +105,9 @@ var Avatar = React.createClass({
100
105
className = "commentPhoto"
101
106
/>
102
107
) ;
103
- } ,
104
- getPhotoUrl : function ( author ) {
105
- return 'https://avatars.githubusercontent.com/' + author . GithubUsername + '?s=50' ;
106
108
}
107
- } ) ;
109
+
110
+ getPhotoUrl = ( author ) => {
111
+ return 'https://avatars.githubusercontent.com/' + author . GithubUsername + '?s=50' ;
112
+ } ;
113
+ }
0 commit comments