diff --git a/package.json b/package.json index 319387b5..25851c63 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,8 @@ "mochify": "^5.8.0", "mochify-istanbul": "^2.4.2", "prettier": "^1.13.5", - "react": "^15.6.1", - "react-dom": "^15.6.1", + "react": "^16.4.2", + "react-dom": "^16.4.2", "rimraf": "^2.6.2", "rollup": "^0.60.7", "rollup-plugin-babel": "^3.0.4", diff --git a/src/SplitPane.js b/src/SplitPane.js index 7add08e1..68cc552a 100644 --- a/src/SplitPane.js +++ b/src/SplitPane.js @@ -37,7 +37,7 @@ function getDefaultSize(defaultSize, minSize, maxSize, draggedSize) { } function removeNullChildren(children) { - return React.Children.toArray(children).filter(c => c); + return React.Children.toArray(children).filter(c => c); } class SplitPane extends React.Component { constructor(props) { @@ -65,15 +65,6 @@ class SplitPane extends React.Component { resized: false, pane1Size: primary === 'first' ? initialSize : undefined, pane2Size: primary === 'second' ? initialSize : undefined, - - // previous props that we need in static methods - instanceProps: { - primary, - size, - defaultSize, - minSize, - maxSize, - }, }; } @@ -214,7 +205,6 @@ class SplitPane extends React.Component { // TODO: find a more elegant way to fix this. memoize calls to setSize? // we have to check values since gDSFP is called on every render static setSize(props, state) { - const { instanceProps } = state; const newState = {}; const newSize = @@ -227,43 +217,14 @@ class SplitPane extends React.Component { state.draggedSize ); - const defaultSizeChanged = - props.defaultSize !== instanceProps.defaultSize || - props.minSize !== instanceProps.minSize || - props.maxSize !== instanceProps.maxSize; - - const shouldUpdateSize = - props.size !== undefined - ? props.size !== instanceProps.size - : defaultSizeChanged; - - if ( - props.size !== undefined && - props.size !== state.draggedSize && - shouldUpdateSize - ) { + if (props.size !== undefined) { newState.draggedSize = newSize; } const isPanel1Primary = props.primary === 'first'; - if (shouldUpdateSize || props.primary !== state.instanceProps.primary) { - newState[isPanel1Primary ? 'pane1Size' : 'pane2Size'] = newSize; - } - - // unset the size on the non primary panel - if (props.primary !== state.instanceProps.primary) { - newState[isPanel1Primary ? 'pane2Size' : 'pane1Size'] = undefined; - } - - // update the values in instanceProps - instanceProps.primary = props.primary; - instanceProps.size = props.size; - instanceProps.defaultSize = props.defaultSize; - instanceProps.minSize = props.minSize; - instanceProps.maxSize = props.maxSize; - - newState.instanceProps = instanceProps; + newState[isPanel1Primary ? 'pane1Size' : 'pane2Size'] = newSize; + newState[isPanel1Primary ? 'pane2Size' : 'pane1Size'] = undefined; return newState; } @@ -296,7 +257,7 @@ class SplitPane extends React.Component { : resizerClassName; const notNullChildren = removeNullChildren(children); - + const style = Object.assign( {}, { diff --git a/test/assertions/Asserter.js b/test/assertions/Asserter.js index 9a21a2e4..6bea9a5d 100644 --- a/test/assertions/Asserter.js +++ b/test/assertions/Asserter.js @@ -217,5 +217,10 @@ export default (jsx, renderToDom = false) => { expect(primary.props.size).to.equal(undefined); expect(secondary.props.size).to.equal(50); }, + + assertPaneWidthChange(newJsx, expectedWidth, pane = 'first') { + updateComponent(newJsx); + return assertPaneStyles({ width: expectedWidth }, pane); + }, }; }; diff --git a/test/default-split-pane-tests.js b/test/default-split-pane-tests.js index bab5b039..a8895e4d 100644 --- a/test/default-split-pane-tests.js +++ b/test/default-split-pane-tests.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { StrictMode } from 'react'; import chai from 'chai'; import spies from 'chai-spies'; @@ -145,7 +145,6 @@ describe('Component updates', () => {