Skip to content

Commit 39a1b51

Browse files
committed
removed componentWillReceiveProps
1 parent 29cf222 commit 39a1b51

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ styles.min.css
55
styles.min.css.map
66
coverage
77
npm-debug.log
8+
package-lock.json

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ webpack.config.*.js
1313
babel.preprocess.sass.js
1414
codecov.yml
1515
.travis.yml
16+
package-lock.json

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"prop-types": "^15.5.7"
5454
},
5555
"peerDependencies": {
56-
"react": "^0.14.0 || ^15.0.0 || ^16.0.0",
57-
"react-dom": "^0.14.0 || ^15.0.0 || ^16.0.0"
56+
"react": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
57+
"react-dom": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
5858
},
5959
"devDependencies": {
6060
"@kadira/storybook": "^1.36.0",
@@ -90,21 +90,21 @@
9090
"html-webpack-plugin": "^2.16.1",
9191
"isparta-loader": "^2.0.0",
9292
"node-libs-browser": "^0.5.2",
93-
"node-sass": "^3.7.0",
93+
"node-sass": "^4.11.0",
9494
"postcss-loader": "^0.9.1",
9595
"qs": "^6.2.0",
9696
"raw-loader": "^0.5.1",
97-
"react": "^15.4.2",
97+
"react": "^16.0.0",
9898
"react-addons-pure-render-mixin": "^15.0.2",
9999
"react-addons-shallow-compare": "^15.1.0",
100100
"react-addons-test-utils": "^15.1.0",
101-
"react-dom": "^15.4.2",
101+
"react-dom": "^16.0.0",
102102
"react-infinite": "^0.9.2",
103103
"react-tiny-virtual-list": "^2.0.1",
104104
"react-virtualized": "^9.2.2",
105105
"redux": "^3.5.2",
106106
"rimraf": "^2.5.2",
107-
"sass-loader": "^3.2.0",
107+
"sass-loader": "^7.1.0",
108108
"stack-source-map": "^1.0.4",
109109
"style-loader": "^0.13.1",
110110
"webpack": "^1.9.11",

src/SortableContainer/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
162162
!this.state.sorting
163163
) {
164164
const {useDragHandle} = this.props;
165-
const {index, collection} = node.sortableInfo;
165+
const {index, collection, disabled} = node.sortableInfo;
166+
167+
if (disabled) {
168+
return;
169+
}
166170

167171
if (
168172
useDragHandle && !closest(e.target, el => el.sortableHandle != null)

src/SortableElement/index.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,48 @@ export default function sortableElement(WrappedComponent, config = {withRef: fal
2525
};
2626

2727
componentDidMount() {
28-
const {collection, disabled, index} = this.props;
29-
30-
if (!disabled) {
31-
this.setDraggable(collection, index);
32-
}
28+
this.register();
3329
}
3430

35-
componentWillReceiveProps(nextProps) {
36-
if (this.props.index !== nextProps.index && this.node) {
37-
this.node.sortableInfo.index = nextProps.index;
38-
}
39-
if (this.props.disabled !== nextProps.disabled) {
40-
const {collection, disabled, index} = nextProps;
41-
if (disabled) {
42-
this.removeDraggable(collection);
43-
} else {
44-
this.setDraggable(collection, index);
31+
componentDidUpdate(prevProps) {
32+
if (this.node) {
33+
if (prevProps.index !== this.props.index) {
34+
this.node.sortableInfo.index = this.props.index;
35+
}
36+
37+
if (prevProps.disabled !== this.props.disabled) {
38+
this.node.sortableInfo.disabled = this.props.disabled;
4539
}
46-
} else if (this.props.collection !== nextProps.collection) {
47-
this.removeDraggable(this.props.collection);
48-
this.setDraggable(nextProps.collection, nextProps.index);
40+
}
41+
42+
if (prevProps.collection !== this.props.collection) {
43+
this.unregister(prevProps.collection);
44+
this.register();
4945
}
5046
}
5147

5248
componentWillUnmount() {
53-
const {collection, disabled} = this.props;
54-
55-
if (!disabled) this.removeDraggable(collection);
49+
this.unregister();
5650
}
5751

58-
setDraggable(collection, index) {
59-
const node = (this.node = findDOMNode(this));
52+
register() {
53+
const {collection, disabled, index} = this.props;
54+
const node = findDOMNode(this);
6055

6156
node.sortableInfo = {
6257
index,
6358
collection,
59+
disabled,
6460
manager: this.context.manager,
6561
};
6662

63+
this.node = node;
6764
this.ref = {node};
65+
6866
this.context.manager.add(collection, this.ref);
69-
}
67+
}
7068

71-
removeDraggable(collection) {
69+
unregister(collection = this.props.collection) {
7270
this.context.manager.remove(collection, this.ref);
7371
}
7472

0 commit comments

Comments
 (0)