Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 28dd69e

Browse files
committed
Performance improvements (WIP) Addresses #427
1 parent f6f2491 commit 28dd69e

File tree

6 files changed

+46
-48
lines changed

6 files changed

+46
-48
lines changed

examples/stress-test/app.js

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { Component } from 'react';
22
import ReactDOM from 'react-dom';
33

4+
window.React = require('react/lib/ReactWithAddons');
5+
46
import { Provider, connect } from 'react-redux';
57
import {
68
Control,
@@ -10,50 +12,42 @@ import {
1012

1113
import store from './store.js';
1214

13-
const UPDATE_ON = 'change';
15+
const UPDATE_ON = 'blur';
16+
17+
class Rows extends Component {
18+
constructor() {
19+
super();
1420

15-
const Rows = connect(({ rows }) => ({ rows }))(class extends Component {
16-
constructor(props) {
17-
super(props);
18-
const { rows } = props;
21+
const rows = Array(100).fill({
22+
name: '',
23+
email: '',
24+
active: false,
25+
});
1926

2027
this.state = {
21-
rendered: rows.map((row, i) =>
22-
<tr key={i}>
23-
<td>
24-
<Control.text
25-
updateOn={UPDATE_ON}
26-
model={`rows[${i}].name`}
27-
/>
28-
</td>
29-
<td>
30-
<Control.text
31-
updateOn={UPDATE_ON}
32-
model={`rows[${i}].email`}
33-
/>
34-
</td>
35-
<td>
36-
<Field
37-
updateOn={UPDATE_ON}
38-
model={`rows[${i}].active`}
39-
>
40-
<label>
41-
<input type="radio" value />
42-
Active
43-
</label>
44-
<label>
45-
<input type="radio" value={false} />
46-
Inactive
47-
</label>
48-
</Field>
49-
</td>
50-
</tr>
51-
),
52-
};
28+
rows,
29+
rendered: rows.map((row, i) => (
30+
<tr key={i}>
31+
<td>
32+
<Control.text
33+
updateOn={UPDATE_ON}
34+
model={`rows[${i}].name`}
35+
placeholder="Name"
36+
/>
37+
<Control.text
38+
updateOn={UPDATE_ON}
39+
model={`rows[${i}].email`}
40+
placeholder="Email"
41+
/>
42+
<Control.checkbox
43+
model={`rows[${i}].active`}
44+
/>
45+
</td>
46+
</tr>
47+
)),
48+
}
5349
}
5450
render() {
55-
const { rows } = this.props;
56-
5751
return (
5852
<section>
5953
<table>
@@ -64,7 +58,7 @@ const Rows = connect(({ rows }) => ({ rows }))(class extends Component {
6458
</section>
6559
);
6660
}
67-
});
61+
};
6862

6963
class StressForm extends Component {
7064
render() {

examples/stress-test/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import thunk from 'redux-thunk';
66
import createLogger from 'redux-logger';
77
import { combineForms } from 'react-redux-form';
88

9-
const initialState = Array(100)
9+
const initialState = Array(1000)
1010
.fill({
1111
name: '',
1212
email: '',

examples/webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ module.exports = {
3737
plugins: [
3838
new webpack.optimize.CommonsChunkPlugin('shared.js'),
3939
new webpack.DefinePlugin({
40-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
40+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
4141
})
4242
]
43-
4443
};

src/components/control-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class Control extends Component {
151151

152152
shouldComponentUpdate(nextProps, nextState) {
153153
const result =
154-
!shallowEqual(this.props, nextProps, ['controlProps'])
154+
!shallowEqual(this.props, nextProps, ['controlProps', 'mapProps'])
155155
|| !shallowEqual(this.props.controlProps, nextProps.controlProps)
156156
|| !shallowEqual(this.state.viewValue, nextState.viewValue);
157157

src/utils/deep-compare-children.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import shallowCompare from 'react/lib/shallowCompare';
33
import shallowEqual from './shallow-equal';
44

5-
function compareChildren(props, nextProps) {
5+
export function compareChildren(props, nextProps) {
66
const { children } = props;
77
const { children: nextChildren } = nextProps;
88

src/utils/resolve-model.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component, PropTypes } from 'react';
2+
import shallowEqual from './shallow-equal';
23

34
function resolveModel(model, parentModel) {
45
if (parentModel) {
@@ -20,11 +21,15 @@ export default function wrapWithModelResolver(WrappedComponent) {
2021
super(props, context);
2122

2223
this.model = context.model;
24+
25+
this.resolvedModel = null;
26+
}
27+
shouldComponentUpdate(nextProps) {
28+
return !shallowEqual(this.props, nextProps);
2329
}
2430
render() {
25-
const resolvedModel = resolveModel(
26-
this.props.model,
27-
this.model);
31+
const resolvedModel = this.resolvedModel
32+
|| resolveModel(this.props.model, this.model);
2833

2934
return <WrappedComponent {...this.props} model={resolvedModel} />;
3035
}

0 commit comments

Comments
 (0)