33 * All rights reserved.
44 *
55 * 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
77 * of patent rights can be found in the PATENTS file in the same directory.
88 */
99
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 ) => {
2425 var nextPage = this . state . page + 1 ;
2526 this . setState ( {
2627 page : nextPage ,
@@ -40,8 +41,9 @@ var CommentsBox = React.createClass({
4041 } . bind ( this ) ;
4142 xhr . send ( ) ;
4243 evt . preventDefault ( ) ;
43- } ,
44- render : function ( ) {
44+ } ;
45+
46+ render ( ) {
4547 var commentNodes = this . state . comments . map ( function ( comment ) {
4648 return < Comment author = { comment . Author } > { comment . Text } </ Comment > ;
4749 } ) ;
@@ -55,8 +57,9 @@ var CommentsBox = React.createClass({
5557 { this . renderMoreLink ( ) }
5658 </ div >
5759 ) ;
58- } ,
59- renderMoreLink : function ( ) {
60+ }
61+
62+ renderMoreLink = ( ) => {
6063 if ( this . state . loadingMore ) {
6164 return < em > Loading...</ em > ;
6265 } else if ( this . state . hasMore ) {
@@ -68,14 +71,15 @@ var CommentsBox = React.createClass({
6871 } else {
6972 return < em > No more comments</ em > ;
7073 }
71- }
72- } ) ;
74+ } ;
75+ }
76+
77+ class Comment extends React . Component {
78+ static propTypes = {
79+ author : PropTypes . object . isRequired
80+ } ;
7381
74- var Comment = React . createClass ( {
75- propTypes : {
76- author : React . PropTypes . object . isRequired
77- } ,
78- render : function ( ) {
82+ render ( ) {
7983 return (
8084 < li >
8185 < Avatar author = { this . props . author } />
@@ -84,13 +88,14 @@ var Comment = React.createClass({
8488 </ li >
8589 ) ;
8690 }
87- } ) ;
91+ }
92+
93+ class Avatar extends React . Component {
94+ static propTypes = {
95+ author : PropTypes . object . isRequired
96+ } ;
8897
89- var Avatar = React . createClass ( {
90- propTypes : {
91- author : React . PropTypes . object . isRequired
92- } ,
93- render : function ( ) {
98+ render ( ) {
9499 return (
95100 < img
96101 src = { this . getPhotoUrl ( this . props . author ) }
@@ -100,8 +105,9 @@ var Avatar = React.createClass({
100105 className = "commentPhoto"
101106 />
102107 ) ;
103- } ,
104- getPhotoUrl : function ( author ) {
105- return 'https://avatars.githubusercontent.com/' + author . GithubUsername + '?s=50' ;
106108 }
107- } ) ;
109+
110+ getPhotoUrl = ( author ) => {
111+ return 'https://avatars.githubusercontent.com/' + author . GithubUsername + '?s=50' ;
112+ } ;
113+ }
0 commit comments