Skip to content

Commit e7da899

Browse files
committed
Using mixin instead of decorator
1 parent 19b93f1 commit e7da899

11 files changed

+49
-22
lines changed

client/app/bundles/Comments/components/Comment.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import React, { PropTypes } from 'react';
22
import marked from 'marked';
3-
import pureRender from 'pure-render-decorator';
3+
import PureRenderMixin from 'react-addons-pure-render-mixin';
44

5-
@pureRender
65
class Comment extends React.Component {
76
static displayName = 'Comment';
87
static propTypes = {
98
author: PropTypes.string.isRequired,
109
text: PropTypes.string.isRequired,
1110
};
1211

12+
shouldComponentUpdate() {
13+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
14+
}
15+
1316
render() {
1417
const { author, text } = this.props;
1518
const rawMarkup = marked(text, { gfm: true, sanitize: true });

client/app/bundles/Comments/components/CommentBox.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, { PropTypes } from 'react';
2-
import pureRender from 'pure-render-decorator';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
33

44
import CommentForm from './CommentForm';
55
import CommentList from './CommentList';
66

7-
@pureRender
87
class CommentBox extends React.Component {
98
constructor(props, context) {
109
super(props, context);
@@ -18,6 +17,10 @@ class CommentBox extends React.Component {
1817
data: PropTypes.object.isRequired,
1918
};
2019

20+
shouldComponentUpdate() {
21+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
22+
}
23+
2124
componentDidMount() {
2225
const { fetchComments } = this.props.actions;
2326
fetchComments();

client/app/bundles/Comments/components/CommentForm.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import NavItem from 'react-bootstrap/lib/NavItem';
88
import Alert from 'react-bootstrap/lib/Alert';
99
import ReactCSSTransitionGroup from 'react/lib/ReactCSSTransitionGroup';
1010
import _ from 'lodash';
11-
import pureRender from 'pure-render-decorator';
11+
import PureRenderMixin from 'react-addons-pure-render-mixin';
1212

1313
const emptyComment = { author: '', text: '' };
1414
const textPlaceholder = 'Say something using markdown...';
1515

16-
@pureRender
1716
class CommentForm extends React.Component {
1817
constructor(props, context) {
1918
super(props, context);
@@ -33,6 +32,10 @@ class CommentForm extends React.Component {
3332
error: PropTypes.any,
3433
};
3534

35+
shouldComponentUpdate() {
36+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
37+
}
38+
3639
_handleSelect(selectedKey) {
3740
this.setState({ formMode: selectedKey });
3841
}

client/app/bundles/Comments/components/CommentList.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import React, { PropTypes } from 'react';
22
import Immutable from 'immutable';
33
import Alert from 'react-bootstrap/lib/Alert';
44
import ReactCSSTransitionGroup from 'react/lib/ReactCSSTransitionGroup';
5-
import pureRender from 'pure-render-decorator';
5+
import PureRenderMixin from 'react-addons-pure-render-mixin';
66

77
import Comment from './Comment';
88

9-
@pureRender
109
class CommentList extends React.Component {
1110

1211
constructor(props, context) {
@@ -23,6 +22,10 @@ class CommentList extends React.Component {
2322
error: PropTypes.any,
2423
};
2524

25+
shouldComponentUpdate() {
26+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
27+
}
28+
2629
_errorWarning() {
2730
// If there is no error, there is nothing to add to the DOM
2831
if (!this.props.error) return undefined;

client/app/bundles/Comments/components/CommentScreen.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import React, { PropTypes } from 'react';
2-
import pureRender from 'pure-render-decorator';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
33

44
import CommentBox from './CommentBox';
55

6-
@pureRender
76
class CommentScreen extends React.Component {
87
static propTypes = {
98
actions: PropTypes.object.isRequired,
109
data: PropTypes.object.isRequired,
1110
};
1211

12+
shouldComponentUpdate() {
13+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
14+
}
15+
1316
render() {
1417
const { data, actions } = this.props;
1518

client/app/bundles/Comments/components/NonRouterCommentScreen.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PropTypes } from 'react';
22
import { connect } from 'react-redux';
33
import { bindActionCreators } from 'redux';
4-
import pureRender from 'pure-render-decorator';
4+
import PureRenderMixin from 'react-addons-pure-render-mixin';
55

66
import CommentScreen from './CommentScreen';
77
import * as commentsActionCreators from '../actions/commentsActionCreators';
@@ -11,13 +11,16 @@ function select(state) {
1111
return { data: state.$$commentsStore };
1212
}
1313

14-
@pureRender
1514
class NonRouterCommentScreen extends React.Component {
1615
static propTypes = {
1716
dispatch: PropTypes.func.isRequired,
1817
data: PropTypes.object.isRequired,
1918
};
2019

20+
shouldComponentUpdate() {
21+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
22+
}
23+
2124
render() {
2225
const { dispatch, data } = this.props;
2326
const actions = bindActionCreators(commentsActionCreators, dispatch);

client/app/bundles/Comments/components/RouterCommentScreen.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PropTypes } from 'react';
22
import { connect } from 'react-redux';
33
import { bindActionCreators } from 'redux';
4-
import pureRender from 'pure-render-decorator';
4+
import PureRenderMixin from 'react-addons-pure-render-mixin';
55

66
import CommentScreen from './CommentScreen';
77
import * as commentsActionCreators from '../actions/commentsActionCreators';
@@ -11,7 +11,6 @@ function select(state) {
1111
return { data: state.$$commentsStore };
1212
}
1313

14-
@pureRender
1514
class RouterCommentScreen extends React.Component {
1615
static propTypes = {
1716
dispatch: PropTypes.func.isRequired,
@@ -21,6 +20,10 @@ class RouterCommentScreen extends React.Component {
2120
}).isRequired,
2221
};
2322

23+
shouldComponentUpdate() {
24+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
25+
}
26+
2427
_renderNotification() {
2528
const locationState = this.props.location.state;
2629
if (!locationState || !locationState.redirectFrom) return null;

client/app/bundles/Comments/components/SimpleCommentScreen.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import React from 'react';
22
import Immutable from 'immutable';
33
import request from 'axios';
44
import _ from 'lodash';
5-
import pureRender from 'pure-render-decorator';
5+
import PureRenderMixin from 'react-addons-pure-render-mixin';
66

77
import CommentForm from './CommentForm';
88
import CommentList from './CommentList';
99
import metaTagsManager from '../utils/metaTagsManager';
1010

11-
@pureRender
1211
class SimpleCommentScreen extends React.Component {
1312
constructor(props, context) {
1413
super(props, context);
@@ -24,6 +23,10 @@ class SimpleCommentScreen extends React.Component {
2423

2524
static displayName = 'SimpleCommentScreen';
2625

26+
shouldComponentUpdate() {
27+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
28+
}
29+
2730
componentDidMount() {
2831
this._fetchComments();
2932
}

client/app/bundles/Comments/components/TestReactRouter.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React from 'react';
2-
import pureRender from 'pure-render-decorator';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
33

4-
@pureRender
54
export default class TestReactRouter extends React.Component {
5+
shouldComponentUpdate() {
6+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
7+
}
68

79
render() {
810
return (

client/app/bundles/Comments/components/TestReactRouterRedirect.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React from 'react';
2-
import pureRender from 'pure-render-decorator';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
33

4-
@pureRender
54
export default class TestReactRouterRedirect extends React.Component {
5+
shouldComponentUpdate() {
6+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
7+
}
68

79
static checkAuth(nextState, replaceState) {
810
// Hard code this to demonstrate the effect

client/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@
5252
"lodash": "^3.10.1",
5353
"marked": "^0.3.5",
5454
"node-uuid": "^1.4.7",
55-
"pure-render-decorator": "^0.2.0",
5655
"react": "^0.14.3",
57-
"react-addons-shallow-compare": "^0.14.3",
56+
"react-addons-pure-render-mixin": "^0.14.3",
5857
"react-bootstrap": "^0.28.1",
5958
"react-dom": "^0.14.3",
6059
"react-redux": "^4.0.0",

0 commit comments

Comments
 (0)