Skip to content

Commit 4d95cf4

Browse files
committed
Creating a parent component and extending it to other components
1 parent 1cb16f5 commit 4d95cf4

File tree

11 files changed

+29
-54
lines changed

11 files changed

+29
-54
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
3+
4+
export default class BaseComponent extends React.Component {
5+
shouldComponentUpdate() {
6+
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
7+
}
8+
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import React, { PropTypes } from 'react';
2-
import PureRenderMixin from 'react-addons-pure-render-mixin';
32

43
import CommentForm from './CommentForm/CommentForm';
54
import CommentList from './CommentList/CommentList';
65
import css from './CommentBox.scss';
6+
import BaseComponent from '../BaseComponent';
77

8-
export default class CommentBox extends React.Component {
8+
export default class CommentBox extends BaseComponent {
99
static propTypes = {
1010
pollInterval: PropTypes.number.isRequired,
1111
actions: PropTypes.object.isRequired,
1212
data: PropTypes.object.isRequired,
1313
};
1414

15-
shouldComponentUpdate() {
16-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
17-
}
18-
1915
componentDidMount() {
2016
const { fetchComments } = this.props.actions;
2117
fetchComments();

client/app/bundles/comments/components/CommentBox/CommentForm/CommentForm.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ 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 PureRenderMixin from 'react-addons-pure-render-mixin';
11+
12+
import BaseComponent from '../../BaseComponent';
1213

1314
const emptyComment = { author: '', text: '' };
1415
const textPlaceholder = 'Say something using markdown...';
1516

16-
export default class CommentForm extends React.Component {
17+
export default class CommentForm extends BaseComponent {
1718
static propTypes = {
1819
isSaving: PropTypes.bool.isRequired,
1920
actions: PropTypes.object.isRequired,
@@ -36,10 +37,6 @@ export default class CommentForm extends React.Component {
3637
]);
3738
}
3839

39-
shouldComponentUpdate() {
40-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
41-
}
42-
4340
_handleSelect(selectedKey) {
4441
this.setState({ formMode: selectedKey });
4542
}

client/app/bundles/comments/components/CommentBox/CommentList/Comment/Comment.jsx

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

54
import css from './Comment.scss';
5+
import BaseComponent from '../../../BaseComponent';
66

7-
export default class Comment extends React.Component {
7+
export default class Comment extends BaseComponent {
88
static propTypes = {
99
author: PropTypes.string.isRequired,
1010
text: PropTypes.string.isRequired,
1111
};
1212

13-
shouldComponentUpdate() {
14-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
15-
}
16-
1713
render() {
1814
const { author, text } = this.props;
1915
const rawMarkup = marked(text, { gfm: true, sanitize: true });

client/app/bundles/comments/components/CommentBox/CommentList/CommentList.jsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import Immutable from 'immutable';
33
import Alert from 'react-bootstrap/lib/Alert';
44
import ReactCSSTransitionGroup from 'react/lib/ReactCSSTransitionGroup';
55
import _ from 'lodash';
6-
import PureRenderMixin from 'react-addons-pure-render-mixin';
76

87
import Comment from './Comment/Comment';
8+
import BaseComponent from '../../BaseComponent';
99

10-
export default class CommentList extends React.Component {
10+
export default class CommentList extends BaseComponent {
1111
static propTypes = {
1212
$$comments: PropTypes.instanceOf(Immutable.List).isRequired,
1313
error: PropTypes.any,
@@ -20,10 +20,6 @@ export default class CommentList extends React.Component {
2020
_.bindAll(this, '_errorWarning');
2121
}
2222

23-
shouldComponentUpdate() {
24-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
25-
}
26-
2723
_errorWarning() {
2824
// If there is no error, there is nothing to add to the DOM
2925
if (!this.props.error) return null;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { PropTypes } from 'react';
22

33
import CommentBox from '../CommentBox/CommentBox';
4-
54
import css from './CommentScreen.scss';
5+
import BaseComponent from '../BaseComponent';
66

7-
export default class CommentScreen extends React.Component {
7+
export default class CommentScreen extends BaseComponent {
88

99
static propTypes = {
1010
actions: PropTypes.object.isRequired,

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

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

76
import metaTagsManager from 'libs/metaTagsManager';
87
import CommentForm from '../CommentBox/CommentForm/CommentForm';
98
import CommentList from '../CommentBox/CommentList/CommentList';
109
import css from './SimpleCommentScreen.scss';
10+
import BaseComponent from '../BaseComponent';
1111

12-
export default class SimpleCommentScreen extends React.Component {
12+
export default class SimpleCommentScreen extends BaseComponent {
1313
constructor(props, context) {
1414
super(props, context);
1515
this.state = {
@@ -22,10 +22,6 @@ export default class SimpleCommentScreen extends React.Component {
2222
_.bindAll(this, '_fetchComments', '_handleCommentSubmit');
2323
}
2424

25-
shouldComponentUpdate() {
26-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
27-
}
28-
2925
componentDidMount() {
3026
this._fetchComments();
3127
}

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

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

4-
export default class TestReactRouter extends React.Component {
5-
shouldComponentUpdate() {
6-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
7-
}
3+
import BaseComponent from '../BaseComponent';
84

5+
export default class TestReactRouter extends BaseComponent {
96
render() {
107
return (
118
<div className="container">

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

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

4-
export default class TestReactRouterRedirect extends React.Component {
5-
shouldComponentUpdate() {
6-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
7-
}
3+
import BaseComponent from '../BaseComponent';
84

5+
export default class TestReactRouterRedirect extends BaseComponent {
96
static checkAuth(nextState, replaceState) {
107
// Hard code this to demonstrate the effect
118
const notAuthorized = true;

client/app/bundles/comments/containers/NonRouterCommentsContainer.jsx

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

65
import CommentScreen from '../components/CommentScreen/CommentScreen';
76
import * as commentsActionCreators from '../actions/commentsActionCreators';
7+
import BaseComponent from '../components/BaseComponent';
88

99
function select(state) {
1010
// Which part of the Redux global state does our component want to receive as props?
1111
return { data: state.$$commentsStore };
1212
}
1313

14-
class NonRouterCommentsContainer extends React.Component {
14+
class NonRouterCommentsContainer extends BaseComponent {
1515
static propTypes = {
1616
dispatch: PropTypes.func.isRequired,
1717
data: PropTypes.object.isRequired,
1818
};
1919

20-
shouldComponentUpdate() {
21-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
22-
}
23-
2420
render() {
2521
const { dispatch, data } = this.props;
2622
const actions = bindActionCreators(commentsActionCreators, dispatch);

client/app/bundles/comments/containers/RouterCommentsContainer.jsx

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

65
import CommentScreen from '../components/CommentScreen/CommentScreen';
76
import * as commentsActionCreators from '../actions/commentsActionCreators';
7+
import BaseComponent from '../components/BaseComponent';
88

99
function select(state) {
1010
// Which part of the Redux global state does our component want to receive as props?
1111
return { data: state.$$commentsStore };
1212
}
1313

14-
class RouterCommentsContainer extends React.Component {
14+
class RouterCommentsContainer extends BaseComponent {
1515
static propTypes = {
1616
dispatch: PropTypes.func.isRequired,
1717
data: PropTypes.object.isRequired,
@@ -20,10 +20,6 @@ class RouterCommentsContainer extends React.Component {
2020
}).isRequired,
2121
};
2222

23-
shouldComponentUpdate() {
24-
return PureRenderMixin.shouldComponentUpdate.apply(this, arguments);
25-
}
26-
2723
render() {
2824
const { dispatch, data } = this.props;
2925
const actions = bindActionCreators(commentsActionCreators, dispatch);

0 commit comments

Comments
 (0)