-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetNode.js
49 lines (45 loc) · 2.02 KB
/
getNode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const isEqual = require('lodash/isEqual')
const PropTypes = require('prop-types')
const React = require('react')
const ImmutablePropTypes = require('react-immutable-proptypes')
module.exports = function getNode(WrappedNode) {
return class Node extends React.Component {
static displayName = 'Node'
static propTypes = {
ancestors: ImmutablePropTypes.list.isRequired,
descendents: ImmutablePropTypes.set.isRequired,
descenders: ImmutablePropTypes.list.isRequired,
disabledDescendents: ImmutablePropTypes.set.isRequired,
hiddenDescendents: ImmutablePropTypes.set.isRequired,
isDisabled: PropTypes.bool.isRequired,
isSelected: PropTypes.bool.isRequired,
isUnselectable: PropTypes.bool.isRequired,
onEvent: PropTypes.func.isRequired,
selectedDescendents: ImmutablePropTypes.set.isRequired,
style: PropTypes.object,
}
onEvent = options => {
this.props.onEvent({
...this.props,
...options,
})
}
shouldComponentUpdate(nextProps) {
return (
nextProps.isDisabled !== this.props.isDisabled ||
nextProps.isSelected !== this.props.isSelected ||
nextProps.isUnselectable !== this.props.isUnselectable ||
!nextProps.ancestors.equals(this.props.ancestors) ||
!nextProps.descendents.equals(this.props.descendents) ||
!nextProps.descenders.equals(this.props.descenders) ||
!nextProps.disabledDescendents.equals(this.props.disabledDescendents) ||
!nextProps.hiddenDescendents.equals(this.props.hiddenDescendents) ||
!nextProps.selectedDescendents.equals(this.props.selectedDescendents) ||
!isEqual(nextProps.style, this.props.style)
)
}
render() {
return <WrappedNode {...this.props} onEvent={this.onEvent} />
}
}
}