victory-shared-events 30.6.1 → 31.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
27
27
  import React from "react";
28
28
  import PropTypes from "prop-types";
29
29
  import { PropTypes as CustomPropTypes, Events, Helpers, Timer } from "victory-core";
30
+ import isEqual from "react-fast-compare";
30
31
 
31
32
  var VictorySharedEvents =
32
33
  /*#__PURE__*/
@@ -55,11 +56,15 @@ function (_React$Component) {
55
56
  };
56
57
  }
57
58
  }, {
58
- key: "componentWillReceiveProps",
59
- value: function componentWillReceiveProps(newProps) {
60
- this.baseProps = this.getBaseProps(newProps);
61
- var externalMutations = this.getExternalMutations(newProps, this.baseProps);
62
- this.applyExternalMutations(newProps, externalMutations);
59
+ key: "shouldComponentUpdate",
60
+ value: function shouldComponentUpdate(nextProps) {
61
+ if (!isEqual(this.props, nextProps)) {
62
+ this.baseProps = this.getBaseProps(nextProps);
63
+ var externalMutations = this.getExternalMutations(nextProps, this.baseProps);
64
+ this.applyExternalMutations(nextProps, externalMutations);
65
+ }
66
+
67
+ return true;
63
68
  }
64
69
  }, {
65
70
  key: "getTimer",
@@ -21,6 +21,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
21
21
 
22
22
  var _victoryCore = require("victory-core");
23
23
 
24
+ var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
25
+
24
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
27
 
26
28
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
@@ -70,11 +72,15 @@ function (_React$Component) {
70
72
  };
71
73
  }
72
74
  }, {
73
- key: "componentWillReceiveProps",
74
- value: function componentWillReceiveProps(newProps) {
75
- this.baseProps = this.getBaseProps(newProps);
76
- var externalMutations = this.getExternalMutations(newProps, this.baseProps);
77
- this.applyExternalMutations(newProps, externalMutations);
75
+ key: "shouldComponentUpdate",
76
+ value: function shouldComponentUpdate(nextProps) {
77
+ if (!(0, _reactFastCompare.default)(this.props, nextProps)) {
78
+ this.baseProps = this.getBaseProps(nextProps);
79
+ var externalMutations = this.getExternalMutations(nextProps, this.baseProps);
80
+ this.applyExternalMutations(nextProps, externalMutations);
81
+ }
82
+
83
+ return true;
78
84
  }
79
85
  }, {
80
86
  key: "getTimer",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-shared-events",
3
- "version": "30.6.1",
3
+ "version": "31.2.0",
4
4
  "description": "Shared Event Helper for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -21,7 +21,8 @@
21
21
  "dependencies": {
22
22
  "lodash": "^4.17.5",
23
23
  "prop-types": "^15.5.8",
24
- "victory-core": "^30.6.1"
24
+ "react-fast-compare": "^2.0.0",
25
+ "victory-core": "^31.2.0"
25
26
  },
26
27
  "scripts": {
27
28
  "version": "nps build-libs && nps build-dists"
@@ -2,6 +2,7 @@ import { assign, isFunction, defaults, isEmpty, fromPairs } from "lodash";
2
2
  import React from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import { PropTypes as CustomPropTypes, Events, Helpers, Timer } from "victory-core";
5
+ import isEqual from "react-fast-compare";
5
6
 
6
7
  export default class VictorySharedEvents extends React.Component {
7
8
  static displayName = "VictorySharedEvents";
@@ -9,10 +10,7 @@ export default class VictorySharedEvents extends React.Component {
9
10
  static role = "shared-event-wrapper";
10
11
 
11
12
  static propTypes = {
12
- children: PropTypes.oneOfType([
13
- PropTypes.arrayOf(PropTypes.node),
14
- PropTypes.node
15
- ]),
13
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
16
14
  container: PropTypes.node,
17
15
  eventKey: PropTypes.oneOfType([
18
16
  PropTypes.array,
@@ -20,42 +18,37 @@ export default class VictorySharedEvents extends React.Component {
20
18
  CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
21
19
  PropTypes.string
22
20
  ]),
23
- events: PropTypes.arrayOf(PropTypes.shape({
24
- childName: PropTypes.oneOfType([
25
- PropTypes.string,
26
- PropTypes.array
27
- ]),
28
- eventHandlers: PropTypes.object,
29
- eventKey: PropTypes.oneOfType([
30
- PropTypes.array,
31
- PropTypes.func,
32
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
33
- PropTypes.string
34
- ]),
35
- target: PropTypes.string
36
- })),
37
- externalEventMutations: PropTypes.arrayOf(PropTypes.shape({
38
- callback: PropTypes.function,
39
- childName: PropTypes.oneOfType([
40
- PropTypes.string,
41
- PropTypes.array
42
- ]),
43
- eventKey: PropTypes.oneOfType([
44
- PropTypes.array,
45
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
46
- PropTypes.string
47
- ]),
48
- mutation: PropTypes.function,
49
- target: PropTypes.oneOfType([
50
- PropTypes.string,
51
- PropTypes.array
52
- ])
53
- })),
21
+ events: PropTypes.arrayOf(
22
+ PropTypes.shape({
23
+ childName: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
24
+ eventHandlers: PropTypes.object,
25
+ eventKey: PropTypes.oneOfType([
26
+ PropTypes.array,
27
+ PropTypes.func,
28
+ CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
29
+ PropTypes.string
30
+ ]),
31
+ target: PropTypes.string
32
+ })
33
+ ),
34
+ externalEventMutations: PropTypes.arrayOf(
35
+ PropTypes.shape({
36
+ callback: PropTypes.function,
37
+ childName: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
38
+ eventKey: PropTypes.oneOfType([
39
+ PropTypes.array,
40
+ CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
41
+ PropTypes.string
42
+ ]),
43
+ mutation: PropTypes.function,
44
+ target: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
45
+ })
46
+ ),
54
47
  groupComponent: PropTypes.node
55
48
  };
56
49
 
57
50
  static defaultProps = {
58
- groupComponent: <g/>
51
+ groupComponent: <g />
59
52
  };
60
53
 
61
54
  static contextTypes = {
@@ -81,13 +74,15 @@ export default class VictorySharedEvents extends React.Component {
81
74
  };
82
75
  }
83
76
 
84
- componentWillReceiveProps(newProps) {
85
- this.baseProps = this.getBaseProps(newProps);
86
- const externalMutations = this.getExternalMutations(newProps, this.baseProps);
87
- this.applyExternalMutations(newProps, externalMutations);
77
+ shouldComponentUpdate(nextProps) {
78
+ if (!isEqual(this.props, nextProps)) {
79
+ this.baseProps = this.getBaseProps(nextProps);
80
+ const externalMutations = this.getExternalMutations(nextProps, this.baseProps);
81
+ this.applyExternalMutations(nextProps, externalMutations);
82
+ }
83
+ return true;
88
84
  }
89
85
 
90
-
91
86
  getTimer() {
92
87
  if (this.context.getTimer) {
93
88
  return this.context.getTimer();
@@ -102,8 +97,9 @@ export default class VictorySharedEvents extends React.Component {
102
97
  const components = ["container", "groupComponent"];
103
98
  const componentEvents = Events.getComponentEvents(props, components);
104
99
  if (Array.isArray(componentEvents)) {
105
- return Array.isArray(props.events) ?
106
- componentEvents.concat(...props.events) : componentEvents;
100
+ return Array.isArray(props.events)
101
+ ? componentEvents.concat(...props.events)
102
+ : componentEvents;
107
103
  }
108
104
  return props.events;
109
105
  }
@@ -114,18 +110,24 @@ export default class VictorySharedEvents extends React.Component {
114
110
  memo = isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo;
115
111
  return memo;
116
112
  }, []);
117
- const compiledCallbacks = callbacks.length ?
118
- () => { callbacks.forEach((c) => c()); } : undefined;
113
+ const compiledCallbacks = callbacks.length
114
+ ? () => {
115
+ callbacks.forEach((c) => c());
116
+ }
117
+ : undefined;
119
118
  this.setState(externalMutations, compiledCallbacks);
120
119
  }
121
120
  }
122
121
 
123
122
  getExternalMutations(props, baseProps) {
124
- return !isEmpty(props.externalEventMutations) ?
125
- Events.getExternalMutationsWithChildren(
126
- props.externalEventMutations, baseProps, this.state, Object.keys(baseProps)
127
- ) :
128
- undefined;
123
+ return !isEmpty(props.externalEventMutations)
124
+ ? Events.getExternalMutationsWithChildren(
125
+ props.externalEventMutations,
126
+ baseProps,
127
+ this.state,
128
+ Object.keys(baseProps)
129
+ )
130
+ : undefined;
129
131
  }
130
132
 
131
133
  getBaseProps(props) {
@@ -161,14 +163,15 @@ export default class VictorySharedEvents extends React.Component {
161
163
  return memo.concat(results);
162
164
  } else if (child.type && isFunction(child.type.getBaseProps)) {
163
165
  const name = child.props.name || childNames[index];
164
- const childEvents = Array.isArray(events) &&
166
+ const childEvents =
167
+ Array.isArray(events) &&
165
168
  events.filter((event) => {
166
169
  if (event.target === "parent") {
167
170
  return false;
168
171
  }
169
- return Array.isArray(event.childName) ?
170
- event.childName.indexOf(name) > -1 :
171
- event.childName === name || event.childName === "all";
172
+ return Array.isArray(event.childName)
173
+ ? event.childName.indexOf(name) > -1
174
+ : event.childName === name || event.childName === "all";
172
175
  });
173
176
  const sharedEvents = {
174
177
  events: childEvents,
@@ -177,10 +180,12 @@ export default class VictorySharedEvents extends React.Component {
177
180
  // partially apply child name
178
181
  getEventState: (key, target) => this.getEventState(key, target, name)
179
182
  };
180
- return memo.concat(React.cloneElement(child, assign(
181
- { key: `events-${name}`, sharedEvents, eventKey, name },
182
- child.props
183
- )));
183
+ return memo.concat(
184
+ React.cloneElement(
185
+ child,
186
+ assign({ key: `events-${name}`, sharedEvents, eventKey, name }, child.props)
187
+ )
188
+ );
184
189
  } else {
185
190
  return memo.concat(child);
186
191
  }
@@ -193,15 +198,16 @@ export default class VictorySharedEvents extends React.Component {
193
198
 
194
199
  getContainer(props, baseProps, events) {
195
200
  const children = this.getNewChildren(props, baseProps);
196
- const parents = Array.isArray(events) &&
197
- events.filter((event) => event.target === "parent");
198
- const sharedEvents = parents.length > 0 ?
199
- {
200
- events: parents,
201
- // partially apply childName (null) and baseProps,
202
- getEvents: (evts, target) => this.getScopedEvents(evts, target, null, baseProps),
203
- getEventState: this.getEventState
204
- } : null;
201
+ const parents = Array.isArray(events) && events.filter((event) => event.target === "parent");
202
+ const sharedEvents =
203
+ parents.length > 0
204
+ ? {
205
+ events: parents,
206
+ // partially apply childName (null) and baseProps,
207
+ getEvents: (evts, target) => this.getScopedEvents(evts, target, null, baseProps),
208
+ getEventState: this.getEventState
209
+ }
210
+ : null;
205
211
  const container = props.container || props.groupComponent;
206
212
  const role = container.type && container.type.role;
207
213
  const containerProps = container.props || {};
@@ -215,11 +221,13 @@ export default class VictorySharedEvents extends React.Component {
215
221
  { children }
216
222
  );
217
223
  const containerEvents = defaults(
218
- {}, Events.getPartialEvents(parentEvents, "parent", parentProps), containerProps.events
224
+ {},
225
+ Events.getPartialEvents(parentEvents, "parent", parentProps),
226
+ containerProps.events
219
227
  );
220
- return role === "container" ?
221
- React.cloneElement(container, assign({}, parentProps, { events: containerEvents })) :
222
- React.cloneElement(container, containerEvents, children);
228
+ return role === "container"
229
+ ? React.cloneElement(container, assign({}, parentProps, { events: containerEvents }))
230
+ : React.cloneElement(container, containerEvents, children);
223
231
  }
224
232
 
225
233
  render() {