victory-stack 31.1.0 → 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.
@@ -1,3 +1,4 @@
1
+ import _isEmpty from "lodash/isEmpty";
1
2
  import _defaults from "lodash/defaults";
2
3
  import _assign from "lodash/assign";
3
4
 
@@ -22,6 +23,7 @@ import React from "react";
22
23
  import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper } from "victory-core";
23
24
  import { VictorySharedEvents } from "victory-shared-events";
24
25
  import { getChildren, getCalculatedProps } from "./helper-methods";
26
+ import isEqual from "react-fast-compare";
25
27
  var fallbackProps = {
26
28
  width: 450,
27
29
  height: 300,
@@ -47,27 +49,23 @@ function (_React$Component) {
47
49
  animating: true
48
50
  };
49
51
  _this.setAnimationState = Wrapper.setAnimationState.bind(_assertThisInitialized(_this));
50
- _this.events = Wrapper.getAllEvents(props);
51
52
  }
52
53
 
53
54
  return _this;
54
55
  }
55
56
 
56
57
  _createClass(VictoryStack, [{
57
- key: "componentWillMount",
58
- value: function componentWillMount() {
59
- this.events = Wrapper.getAllEvents(this.props);
60
- }
61
- }, {
62
- key: "componentWillReceiveProps",
63
- value: function componentWillReceiveProps(nextProps) {
58
+ key: "shouldComponentUpdate",
59
+ value: function shouldComponentUpdate(nextProps) {
64
60
  if (this.props.animate) {
65
- this.setAnimationState(this.props, nextProps);
61
+ if (!isEqual(this.props, nextProps)) {
62
+ this.setAnimationState(this.props, nextProps);
63
+ return false;
64
+ }
66
65
  }
67
66
 
68
- this.events = Wrapper.getAllEvents(nextProps);
69
- } // the old ones were bad
70
-
67
+ return true;
68
+ }
71
69
  }, {
72
70
  key: "getNewChildren",
73
71
  value: function getNewChildren(props, childComponents, calculatedProps) {
@@ -132,12 +130,13 @@ function (_React$Component) {
132
130
  var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
133
131
  var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
134
132
  var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent;
133
+ var events = Wrapper.getAllEvents(props);
135
134
 
136
- if (this.events) {
135
+ if (!_isEmpty(events)) {
137
136
  return React.createElement(VictorySharedEvents, {
138
137
  container: container,
139
138
  eventKey: eventKey,
140
- events: this.events,
139
+ events: events,
141
140
  externalEventMutations: externalEventMutations
142
141
  }, newChildren);
143
142
  }
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
9
+
8
10
  var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
9
11
 
10
12
  var _assign2 = _interopRequireDefault(require("lodash/assign"));
@@ -19,6 +21,8 @@ var _victorySharedEvents = require("victory-shared-events");
19
21
 
20
22
  var _helperMethods = require("./helper-methods");
21
23
 
24
+ var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
25
+
22
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
27
 
24
28
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
@@ -62,27 +66,23 @@ function (_React$Component) {
62
66
  animating: true
63
67
  };
64
68
  _this.setAnimationState = _victoryCore.Wrapper.setAnimationState.bind(_assertThisInitialized(_this));
65
- _this.events = _victoryCore.Wrapper.getAllEvents(props);
66
69
  }
67
70
 
68
71
  return _this;
69
72
  }
70
73
 
71
74
  _createClass(VictoryStack, [{
72
- key: "componentWillMount",
73
- value: function componentWillMount() {
74
- this.events = _victoryCore.Wrapper.getAllEvents(this.props);
75
- }
76
- }, {
77
- key: "componentWillReceiveProps",
78
- value: function componentWillReceiveProps(nextProps) {
75
+ key: "shouldComponentUpdate",
76
+ value: function shouldComponentUpdate(nextProps) {
79
77
  if (this.props.animate) {
80
- this.setAnimationState(this.props, nextProps);
78
+ if (!(0, _reactFastCompare.default)(this.props, nextProps)) {
79
+ this.setAnimationState(this.props, nextProps);
80
+ return false;
81
+ }
81
82
  }
82
83
 
83
- this.events = _victoryCore.Wrapper.getAllEvents(nextProps);
84
- } // the old ones were bad
85
-
84
+ return true;
85
+ }
86
86
  }, {
87
87
  key: "getNewChildren",
88
88
  value: function getNewChildren(props, childComponents, calculatedProps) {
@@ -152,11 +152,13 @@ function (_React$Component) {
152
152
  var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
153
153
  var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent;
154
154
 
155
- if (this.events) {
155
+ var events = _victoryCore.Wrapper.getAllEvents(props);
156
+
157
+ if (!(0, _isEmpty2.default)(events)) {
156
158
  return _react.default.createElement(_victorySharedEvents.VictorySharedEvents, {
157
159
  container: container,
158
160
  eventKey: eventKey,
159
- events: this.events,
161
+ events: events,
160
162
  externalEventMutations: externalEventMutations
161
163
  }, newChildren);
162
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-stack",
3
- "version": "31.1.0",
3
+ "version": "31.2.0",
4
4
  "description": "Stack Layout Component 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": "^31.1.0"
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"
@@ -1,9 +1,10 @@
1
- import { assign, defaults } from "lodash";
1
+ import { assign, defaults, isEmpty } from "lodash";
2
2
  import PropTypes from "prop-types";
3
3
  import React from "react";
4
4
  import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper } from "victory-core";
5
5
  import { VictorySharedEvents } from "victory-shared-events";
6
6
  import { getChildren, getCalculatedProps } from "./helper-methods";
7
+ import isEqual from "react-fast-compare";
7
8
 
8
9
  const fallbackProps = {
9
10
  width: 450,
@@ -73,22 +74,19 @@ export default class VictoryStack extends React.Component {
73
74
  animating: true
74
75
  };
75
76
  this.setAnimationState = Wrapper.setAnimationState.bind(this);
76
- this.events = Wrapper.getAllEvents(props);
77
77
  }
78
78
  }
79
79
 
80
- componentWillMount() {
81
- this.events = Wrapper.getAllEvents(this.props);
82
- }
83
-
84
- componentWillReceiveProps(nextProps) {
80
+ shouldComponentUpdate(nextProps) {
85
81
  if (this.props.animate) {
86
- this.setAnimationState(this.props, nextProps);
82
+ if (!isEqual(this.props, nextProps)) {
83
+ this.setAnimationState(this.props, nextProps);
84
+ return false;
85
+ }
87
86
  }
88
- this.events = Wrapper.getAllEvents(nextProps);
87
+ return true;
89
88
  }
90
89
 
91
- // the old ones were bad
92
90
  getNewChildren(props, childComponents, calculatedProps) {
93
91
  const children = getChildren(props, childComponents, calculatedProps);
94
92
  const getAnimationProps = Wrapper.getAnimationProps.bind(this);
@@ -140,12 +138,13 @@ export default class VictoryStack extends React.Component {
140
138
  const container = standalone
141
139
  ? this.renderContainer(containerComponent, containerProps)
142
140
  : groupComponent;
143
- if (this.events) {
141
+ const events = Wrapper.getAllEvents(props);
142
+ if (!isEmpty(events)) {
144
143
  return (
145
144
  <VictorySharedEvents
146
145
  container={container}
147
146
  eventKey={eventKey}
148
- events={this.events}
147
+ events={events}
149
148
  externalEventMutations={externalEventMutations}
150
149
  >
151
150
  {newChildren}