Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #236 from facebook/develop
Browse files Browse the repository at this point in the history
sync up for v0.4.2
  • Loading branch information
ehzhang committed Aug 11, 2015
2 parents 5eecacc + ff6ab0d commit 77eef92
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/FixedDataTable.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ var FixedDataTable = React.createClass({
return false;
}

return(
return (
(delta < 0 && this.state.scrollX > 0) ||
(delta >= 0 && this.state.scrollX < this.state.maxScrollX)
);
Expand All @@ -353,7 +353,7 @@ var FixedDataTable = React.createClass({
return false;
}

return(
return (
(delta < 0 && this.state.scrollY > 0) ||
(delta >= 0 && this.state.scrollY < this.state.maxScrollY)
);
Expand Down Expand Up @@ -862,7 +862,11 @@ var FixedDataTable = React.createClass({
totalFixedColumnsWidth += column.props.width;
}

var scrollableColumnIndex = this._columnToScrollTo - fixedColumnsCount;
var scrollableColumnIndex = Math.min(
this._columnToScrollTo - fixedColumnsCount,
columnInfo.bodyScrollableColumns.length - 1,
);

var previousColumnsWidth = 0;
for (i = 0; i < scrollableColumnIndex; ++i) {
column = columnInfo.bodyScrollableColumns[i];
Expand All @@ -871,7 +875,7 @@ var FixedDataTable = React.createClass({

var availableScrollWidth = props.width - totalFixedColumnsWidth;
var selectedColumnWidth = columnInfo.bodyScrollableColumns[
this._columnToScrollTo - fixedColumnsCount
scrollableColumnIndex
].props.width;
var minAcceptableScrollPosition =
previousColumnsWidth + selectedColumnWidth - availableScrollWidth;
Expand Down Expand Up @@ -1043,7 +1047,7 @@ var FixedDataTable = React.createClass({
this.props.headerDataGetter(columnProps.dataKey);
}
return headData;
},
},

_getGroupHeaderData(/*array*/ columnGroups) /*array*/ {
var groupHeaderData = [];
Expand Down
63 changes: 62 additions & 1 deletion src/stubs/react/ReactComponentWithPureRenderMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,65 @@
* @providesModule ReactComponentWithPureRenderMixin
*/

module.exports = require('react/lib/ReactComponentWithPureRenderMixin');
'use strict';

/**
* Performs equality by iterating through keys on an object and returning
* false when any key has values which are not strictly equal between
* objA and objB. Returns true when the values of all keys are strictly equal.
*
* @return {boolean}
*/
function shallowEqual(objA, objB) {
if (objA === objB) {
return true;
}
var key;
// Test for A's keys different from B.
for (key in objA) {
if (objA.hasOwnProperty(key) &&
(!objB.hasOwnProperty(key) || objA[key] !== objB[key])) {
return false;
}
}
// Test for B's keys missing from A.
for (key in objB) {
if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) {
return false;
}
}
return true;
}

/**
* If your React component's render function is "pure", e.g. it will render the
* same result given the same props and state, provide this Mixin for a
* considerable performance boost.
*
* Most React components have pure render functions.
*
* Example:
*
* var ReactComponentWithPureRenderMixin =
* require('ReactComponentWithPureRenderMixin');
* React.createClass({
* mixins: [ReactComponentWithPureRenderMixin],
*
* render: function() {
* return <div className={this.props.className}>foo</div>;
* }
* });
*
* Note: This only checks shallow equality for props and state. If these contain
* complex data structures this mixin may have false-negatives for deeper
* differences. Only mixin to components which have simple props and state, or
* use `forceUpdate()` when you know deep data structures have changed.
*/
var ReactComponentWithPureRenderMixin = {
shouldComponentUpdate: function(nextProps, nextState) {
return !shallowEqual(this.props, nextProps) ||
!shallowEqual(this.state, nextState);
}
};

module.exports = ReactComponentWithPureRenderMixin;

0 comments on commit 77eef92

Please sign in to comment.