@@ -25,50 +25,48 @@ export default function sortableElement(WrappedComponent, config = {withRef: fal
25
25
} ;
26
26
27
27
componentDidMount ( ) {
28
- const { collection, disabled, index} = this . props ;
29
-
30
- if ( ! disabled ) {
31
- this . setDraggable ( collection , index ) ;
32
- }
28
+ this . register ( ) ;
33
29
}
34
30
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 ;
45
39
}
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 ( ) ;
49
45
}
50
46
}
51
47
52
48
componentWillUnmount ( ) {
53
- const { collection, disabled} = this . props ;
54
-
55
- if ( ! disabled ) this . removeDraggable ( collection ) ;
49
+ this . unregister ( ) ;
56
50
}
57
51
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 ) ;
60
55
61
56
node . sortableInfo = {
62
57
index,
63
58
collection,
59
+ disabled,
64
60
manager : this . context . manager ,
65
61
} ;
66
62
63
+ this . node = node ;
67
64
this . ref = { node} ;
65
+
68
66
this . context . manager . add ( collection , this . ref ) ;
69
- }
67
+ }
70
68
71
- removeDraggable ( collection ) {
69
+ unregister ( collection = this . props . collection ) {
72
70
this . context . manager . remove ( collection , this . ref ) ;
73
71
}
74
72
0 commit comments