victory-group 35.11.3 → 36.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.
- package/dist/victory-group.js +991 -858
- package/dist/victory-group.min.js +1 -1
- package/es/helper-methods.js +46 -1
- package/es/index.d.ts +1 -0
- package/es/victory-group.js +96 -162
- package/lib/helper-methods.js +51 -0
- package/lib/index.d.ts +1 -0
- package/lib/victory-group.js +104 -165
- package/package.json +4 -4
- package/src/helper-methods.js +33 -1
- package/src/index.d.ts +1 -0
- package/src/victory-group.js +148 -134
package/es/helper-methods.js
CHANGED
|
@@ -8,8 +8,21 @@ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.
|
|
|
8
8
|
|
|
9
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
10
10
|
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
12
|
+
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
14
|
+
|
|
15
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
16
|
+
|
|
17
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
+
|
|
19
|
+
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; }
|
|
20
|
+
|
|
21
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
|
+
|
|
11
23
|
import React from "react";
|
|
12
|
-
import { Helpers, Scale,
|
|
24
|
+
import { Data, Helpers, Scale, Wrapper } from "victory-core";
|
|
25
|
+
import isEqual from "react-fast-compare";
|
|
13
26
|
var fallbackProps = {
|
|
14
27
|
width: 450,
|
|
15
28
|
height: 300,
|
|
@@ -65,6 +78,38 @@ export function getCalculatedProps(props, childComponents) {
|
|
|
65
78
|
origin: origin,
|
|
66
79
|
padding: padding
|
|
67
80
|
};
|
|
81
|
+
} // We need to remove sharedEvents in order to memoize the calculated data
|
|
82
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
83
|
+
|
|
84
|
+
var withoutSharedEvents = function (props) {
|
|
85
|
+
var children = props.children;
|
|
86
|
+
var modifiedChildren = React.Children.toArray(children).map(function (child) {
|
|
87
|
+
return _objectSpread({}, child, {
|
|
88
|
+
props: Helpers.omit(child.props, ["sharedEvents"])
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
props.children = modifiedChildren;
|
|
92
|
+
return props;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export function useMemoizedProps(initialProps) {
|
|
96
|
+
var modifiedProps = withoutSharedEvents(initialProps);
|
|
97
|
+
|
|
98
|
+
var _React$useState = React.useState(modifiedProps),
|
|
99
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
100
|
+
props = _React$useState2[0],
|
|
101
|
+
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
|
|
102
|
+
// will only be re-calculated when they change.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
React.useEffect(function () {
|
|
106
|
+
if (!isEqual(modifiedProps, props)) {
|
|
107
|
+
setProps(modifiedProps);
|
|
108
|
+
}
|
|
109
|
+
}, [props, setProps, modifiedProps]);
|
|
110
|
+
return React.useMemo(function () {
|
|
111
|
+
return getCalculatedProps(props, props.children);
|
|
112
|
+
}, [props]);
|
|
68
113
|
}
|
|
69
114
|
|
|
70
115
|
function pixelsToValue(props, axis, calculatedProps) {
|
package/es/index.d.ts
CHANGED
package/es/victory-group.js
CHANGED
|
@@ -6,23 +6,11 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
6
|
|
|
7
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
8
|
|
|
9
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
-
|
|
11
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
12
|
-
|
|
13
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
14
|
-
|
|
15
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
16
|
-
|
|
17
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
18
|
-
|
|
19
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
-
|
|
21
9
|
import PropTypes from "prop-types";
|
|
22
10
|
import React from "react";
|
|
23
|
-
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper } from "victory-core";
|
|
11
|
+
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper, Hooks } from "victory-core";
|
|
24
12
|
import { VictorySharedEvents } from "victory-shared-events";
|
|
25
|
-
import { getChildren,
|
|
13
|
+
import { getChildren, useMemoizedProps } from "./helper-methods";
|
|
26
14
|
import isEqual from "react-fast-compare";
|
|
27
15
|
var fallbackProps = {
|
|
28
16
|
width: 450,
|
|
@@ -31,76 +19,46 @@ var fallbackProps = {
|
|
|
31
19
|
offset: 0
|
|
32
20
|
};
|
|
33
21
|
|
|
34
|
-
var VictoryGroup =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var getAnimationProps = Wrapper.getAnimationProps.bind(this);
|
|
75
|
-
return children.map(function (child, index) {
|
|
76
|
-
var childProps = _assign({
|
|
77
|
-
animate: getAnimationProps(props, child, index)
|
|
78
|
-
}, child.props);
|
|
79
|
-
|
|
80
|
-
return React.cloneElement(child, childProps);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
key: "renderContainer",
|
|
85
|
-
value: function renderContainer(containerComponent, props) {
|
|
86
|
-
var containerProps = _defaults({}, containerComponent.props, props);
|
|
87
|
-
|
|
88
|
-
return React.cloneElement(containerComponent, containerProps);
|
|
89
|
-
}
|
|
90
|
-
}, {
|
|
91
|
-
key: "getContainerProps",
|
|
92
|
-
value: function getContainerProps(props, calculatedProps) {
|
|
93
|
-
var width = props.width,
|
|
94
|
-
height = props.height,
|
|
95
|
-
standalone = props.standalone,
|
|
96
|
-
theme = props.theme,
|
|
97
|
-
polar = props.polar,
|
|
98
|
-
horizontal = props.horizontal,
|
|
99
|
-
name = props.name;
|
|
100
|
-
var domain = calculatedProps.domain,
|
|
101
|
-
scale = calculatedProps.scale,
|
|
102
|
-
style = calculatedProps.style,
|
|
103
|
-
origin = calculatedProps.origin;
|
|
22
|
+
var VictoryGroup = function (initialProps) {
|
|
23
|
+
// eslint-disable-next-line no-use-before-define
|
|
24
|
+
var role = VictoryGroupMemo.role;
|
|
25
|
+
|
|
26
|
+
var _Hooks$useAnimationSt = Hooks.useAnimationState(),
|
|
27
|
+
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
|
|
28
|
+
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
|
|
29
|
+
getProps = _Hooks$useAnimationSt.getProps;
|
|
30
|
+
|
|
31
|
+
var props = getProps(initialProps);
|
|
32
|
+
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
33
|
+
var eventKey = modifiedProps.eventKey,
|
|
34
|
+
containerComponent = modifiedProps.containerComponent,
|
|
35
|
+
standalone = modifiedProps.standalone,
|
|
36
|
+
groupComponent = modifiedProps.groupComponent,
|
|
37
|
+
externalEventMutations = modifiedProps.externalEventMutations,
|
|
38
|
+
width = modifiedProps.width,
|
|
39
|
+
height = modifiedProps.height,
|
|
40
|
+
theme = modifiedProps.theme,
|
|
41
|
+
polar = modifiedProps.polar,
|
|
42
|
+
horizontal = modifiedProps.horizontal,
|
|
43
|
+
name = modifiedProps.name;
|
|
44
|
+
var childComponents = React.Children.toArray(modifiedProps.children);
|
|
45
|
+
var calculatedProps = useMemoizedProps(modifiedProps);
|
|
46
|
+
var domain = calculatedProps.domain,
|
|
47
|
+
scale = calculatedProps.scale,
|
|
48
|
+
style = calculatedProps.style,
|
|
49
|
+
origin = calculatedProps.origin;
|
|
50
|
+
var newChildren = React.useMemo(function () {
|
|
51
|
+
var children = getChildren(props, childComponents, calculatedProps);
|
|
52
|
+
return children.map(function (child, index) {
|
|
53
|
+
var childProps = _assign({
|
|
54
|
+
animate: getAnimationProps(props, child, index, "victory-group")
|
|
55
|
+
}, child.props);
|
|
56
|
+
|
|
57
|
+
return React.cloneElement(child, childProps);
|
|
58
|
+
});
|
|
59
|
+
}, [props, childComponents, calculatedProps, getAnimationProps]);
|
|
60
|
+
var containerProps = React.useMemo(function () {
|
|
61
|
+
if (standalone) {
|
|
104
62
|
return {
|
|
105
63
|
domain: domain,
|
|
106
64
|
scale: scale,
|
|
@@ -115,87 +73,63 @@ function (_React$Component) {
|
|
|
115
73
|
name: name
|
|
116
74
|
};
|
|
117
75
|
}
|
|
118
|
-
}, {
|
|
119
|
-
key: "render",
|
|
120
|
-
value: function render() {
|
|
121
|
-
var role = this.constructor.role;
|
|
122
|
-
var props = this.state && this.state.nodesWillExit ? this.state.oldProps || this.props : this.props;
|
|
123
|
-
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
|
|
124
|
-
var eventKey = modifiedProps.eventKey,
|
|
125
|
-
containerComponent = modifiedProps.containerComponent,
|
|
126
|
-
standalone = modifiedProps.standalone,
|
|
127
|
-
groupComponent = modifiedProps.groupComponent,
|
|
128
|
-
externalEventMutations = modifiedProps.externalEventMutations;
|
|
129
|
-
var childComponents = React.Children.toArray(modifiedProps.children);
|
|
130
|
-
var calculatedProps = getCalculatedProps(modifiedProps, childComponents);
|
|
131
|
-
var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
|
|
132
|
-
var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {};
|
|
133
|
-
var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent;
|
|
134
|
-
var events = Wrapper.getAllEvents(props);
|
|
135
76
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
externalEventMutations: externalEventMutations
|
|
142
|
-
}, newChildren);
|
|
143
|
-
}
|
|
77
|
+
return {};
|
|
78
|
+
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, origin, name]);
|
|
79
|
+
var container = React.useMemo(function () {
|
|
80
|
+
if (standalone) {
|
|
81
|
+
var defaultContainerProps = _defaults({}, containerComponent.props, containerProps);
|
|
144
82
|
|
|
145
|
-
return React.cloneElement(
|
|
83
|
+
return React.cloneElement(containerComponent, defaultContainerProps);
|
|
146
84
|
}
|
|
147
|
-
}]);
|
|
148
85
|
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
colorScale: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]),
|
|
172
|
-
horizontal: PropTypes.bool,
|
|
173
|
-
offset: PropTypes.number
|
|
174
|
-
})
|
|
175
|
-
});
|
|
176
|
-
Object.defineProperty(VictoryGroup, "defaultProps", {
|
|
177
|
-
configurable: true,
|
|
178
|
-
enumerable: true,
|
|
179
|
-
writable: true,
|
|
180
|
-
value: {
|
|
181
|
-
containerComponent: React.createElement(VictoryContainer, null),
|
|
182
|
-
groupComponent: React.createElement("g", null),
|
|
183
|
-
samples: 50,
|
|
184
|
-
sortOrder: "ascending",
|
|
185
|
-
standalone: true,
|
|
186
|
-
theme: VictoryTheme.grayscale
|
|
86
|
+
return groupComponent;
|
|
87
|
+
}, [groupComponent, standalone, containerComponent, containerProps]);
|
|
88
|
+
var events = React.useMemo(function () {
|
|
89
|
+
return Wrapper.getAllEvents(props);
|
|
90
|
+
}, [props]);
|
|
91
|
+
var previousProps = Hooks.usePreviousProps(initialProps);
|
|
92
|
+
React.useEffect(function () {
|
|
93
|
+
// This is called before dismount to keep state in sync
|
|
94
|
+
return function () {
|
|
95
|
+
if (initialProps.animate) {
|
|
96
|
+
setAnimationState(previousProps, props);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}, [setAnimationState, previousProps, initialProps, props]);
|
|
100
|
+
|
|
101
|
+
if (!_isEmpty(events)) {
|
|
102
|
+
return React.createElement(VictorySharedEvents, {
|
|
103
|
+
container: container,
|
|
104
|
+
eventKey: eventKey,
|
|
105
|
+
events: events,
|
|
106
|
+
externalEventMutations: externalEventMutations
|
|
107
|
+
}, newChildren);
|
|
187
108
|
}
|
|
109
|
+
|
|
110
|
+
return React.cloneElement(container, container.props, newChildren);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
VictoryGroup.propTypes = _objectSpread({}, CommonProps.baseProps, CommonProps.dataProps, {
|
|
114
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
115
|
+
color: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
116
|
+
colorScale: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]),
|
|
117
|
+
horizontal: PropTypes.bool,
|
|
118
|
+
offset: PropTypes.number
|
|
188
119
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
120
|
+
VictoryGroup.defaultProps = {
|
|
121
|
+
containerComponent: React.createElement(VictoryContainer, null),
|
|
122
|
+
groupComponent: React.createElement("g", null),
|
|
123
|
+
samples: 50,
|
|
124
|
+
sortOrder: "ascending",
|
|
125
|
+
standalone: true,
|
|
126
|
+
theme: VictoryTheme.grayscale
|
|
127
|
+
}; // We need to attatch the static properties to the memoized version, or else
|
|
128
|
+
// VictoryChart will not be able to get this component's role type
|
|
129
|
+
|
|
130
|
+
var VictoryGroupMemo = React.memo(VictoryGroup, isEqual);
|
|
131
|
+
VictoryGroupMemo.displayName = "VictoryGroup";
|
|
132
|
+
VictoryGroupMemo.role = "group";
|
|
133
|
+
VictoryGroupMemo.expectedComponents = ["groupComponent", "containerComponent", "labelComponent"];
|
|
134
|
+
VictoryGroupMemo.getChildren = getChildren;
|
|
135
|
+
export default VictoryGroupMemo;
|
package/lib/helper-methods.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getCalculatedProps = getCalculatedProps;
|
|
7
|
+
exports.useMemoizedProps = useMemoizedProps;
|
|
7
8
|
exports.getChildren = getChildren;
|
|
8
9
|
|
|
9
10
|
var _assign2 = _interopRequireDefault(require("lodash/assign"));
|
|
@@ -12,6 +13,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
12
13
|
|
|
13
14
|
var _victoryCore = require("victory-core");
|
|
14
15
|
|
|
16
|
+
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
|
|
17
|
+
|
|
15
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
19
|
|
|
17
20
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
@@ -22,6 +25,18 @@ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.
|
|
|
22
25
|
|
|
23
26
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
24
27
|
|
|
28
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
29
|
+
|
|
30
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
31
|
+
|
|
32
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
33
|
+
|
|
34
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
39
|
+
|
|
25
40
|
var fallbackProps = {
|
|
26
41
|
width: 450,
|
|
27
42
|
height: 300,
|
|
@@ -84,6 +99,42 @@ function getCalculatedProps(props, childComponents) {
|
|
|
84
99
|
origin: origin,
|
|
85
100
|
padding: padding
|
|
86
101
|
};
|
|
102
|
+
} // We need to remove sharedEvents in order to memoize the calculated data
|
|
103
|
+
// With shared events, the props change on every event, and every value is re-calculated
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
var withoutSharedEvents = function (props) {
|
|
107
|
+
var children = props.children;
|
|
108
|
+
|
|
109
|
+
var modifiedChildren = _react.default.Children.toArray(children).map(function (child) {
|
|
110
|
+
return _objectSpread({}, child, {
|
|
111
|
+
props: _victoryCore.Helpers.omit(child.props, ["sharedEvents"])
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
props.children = modifiedChildren;
|
|
116
|
+
return props;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function useMemoizedProps(initialProps) {
|
|
120
|
+
var modifiedProps = withoutSharedEvents(initialProps);
|
|
121
|
+
|
|
122
|
+
var _React$useState = _react.default.useState(modifiedProps),
|
|
123
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
124
|
+
props = _React$useState2[0],
|
|
125
|
+
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
|
|
126
|
+
// will only be re-calculated when they change.
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
_react.default.useEffect(function () {
|
|
130
|
+
if (!(0, _reactFastCompare.default)(modifiedProps, props)) {
|
|
131
|
+
setProps(modifiedProps);
|
|
132
|
+
}
|
|
133
|
+
}, [props, setProps, modifiedProps]);
|
|
134
|
+
|
|
135
|
+
return _react.default.useMemo(function () {
|
|
136
|
+
return getCalculatedProps(props, props.children);
|
|
137
|
+
}, [props]);
|
|
87
138
|
}
|
|
88
139
|
|
|
89
140
|
function pixelsToValue(props, axis, calculatedProps) {
|
package/lib/index.d.ts
CHANGED