Skip to content

Commit f6e2bb6

Browse files
committed
Created PureDeepRenderMixin to help keep render times fast
1 parent d605dc8 commit f6e2bb6

6 files changed

+36
-4
lines changed

lib/GridItem.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ var React = require('react/addons');
33
var utils = require('./utils');
44
var Draggable = require('react-draggable');
55
var Resizable = require('react-resizable').Resizable;
6+
var PureDeepRenderMixin = require('./PureDeepRenderMixin');
67

78
var GridItem = module.exports = React.createClass({
89
displayName: 'GridItem',
9-
mixins: [React.addons.PureRenderMixin],
10+
mixins: [PureDeepRenderMixin],
1011

1112
propTypes: {
1213
// General grid attributes

lib/PureDeepRenderMixin.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
var deepEqual = require('deep-equal');
3+
4+
// Like PureRenderMixin, but with deep comparisons.
5+
var PureDeepRenderMixin = {
6+
shouldComponentUpdate: function(nextProps, nextState) {
7+
return !deepEqual(this.props, nextProps) ||
8+
!deepEqual(this.state, nextState);
9+
}
10+
};
11+
12+
module.exports = PureDeepRenderMixin;

lib/ReactGridLayout.jsx

+15-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
var React = require('react/addons');
33
var GridItem = require('./GridItem.jsx');
44
var utils = require('./utils');
5+
var PureDeepRenderMixin = require('./PureDeepRenderMixin');
6+
57

68
var ReactGridLayout = module.exports = React.createClass({
79
displayName: 'ReactGridLayout',
8-
// mixins: [React.addons.PureRenderMixin],
10+
mixins: [PureDeepRenderMixin],
911

1012
propTypes: {
1113
// If true, the container height swells and contracts to fit contents
@@ -235,9 +237,15 @@ var ReactGridLayout = module.exports = React.createClass({
235237
placeholder() {
236238
if (!this.state.activeDrag) return '';
237239

240+
// {...this.state.activeDrag} is pretty slow, actually
238241
return (
239242
<GridItem
240-
{...this.state.activeDrag}
243+
w={this.state.activeDrag.w}
244+
h={this.state.activeDrag.h}
245+
x={this.state.activeDrag.x}
246+
y={this.state.activeDrag.y}
247+
i={this.state.activeDrag.i}
248+
placeholder={true}
241249
className="react-grid-placeholder"
242250
containerWidth={this.state.width}
243251
cols={this.state.cols}
@@ -266,7 +274,11 @@ var ReactGridLayout = module.exports = React.createClass({
266274
var moveOnStartChange = drag && drag.i === i ? false : true;
267275
return (
268276
<GridItem
269-
{...l}
277+
w={l.w}
278+
h={l.h}
279+
x={l.x}
280+
y={l.y}
281+
i={l.i}
270282
containerWidth={this.state.width}
271283
cols={this.state.cols}
272284
margin={this.props.margin}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"homepage": "https://github.com/STRML/react-grid-layout",
3131
"dependencies": {
32+
"deep-equal": "^0.2.1",
3233
"react-draggable": "strml/react-draggable",
3334
"react-resizable": "^0.0.3"
3435
},

test/TestLayout.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require('style!css!../node_modules/react-resizable/css/styles.css');
1010

1111
var TestLayout = module.exports = React.createClass({
1212
displayName: 'TestLayout',
13+
mixins: [React.addons.PureRenderMixin],
1314

1415
getDefaultProps() {
1516
return {

webpack-dev-server.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ module.exports = {
2020
},
2121
plugins: [
2222
new webpack.optimize.DedupePlugin(),
23+
new webpack.DefinePlugin({
24+
"process.env": {
25+
NODE_ENV: JSON.stringify('development')
26+
}
27+
}),
2328
],
2429
debug: true,
2530
devtool: "#inline-source-map",

0 commit comments

Comments
 (0)