@koordinates/xstate-tree 4.3.0-beta.5 → 4.3.0-beta.7
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/lib/routing/Link.js +1 -1
- package/lib/testingUtilities.js +1 -1
- package/lib/utils.js +15 -77
- package/package.json +1 -1
package/lib/routing/Link.js
CHANGED
|
@@ -54,7 +54,7 @@ function LinkInner({ to, children, testId, preloadOnHoverMs, preloadOnInteractio
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
: undefined;
|
|
57
|
-
return (react_1.default.createElement("a", { ...props, ref: ref, href: href, "data-testid": testId, onMouseDown: onMouseDown !== null && onMouseDown !== void 0 ? onMouseDown : _onMouseDown, onMouseEnter: onMouseEnter !== null && onMouseEnter !== void 0 ? onMouseEnter : _onMouseEnter, onMouseLeave: onMouseLeave !== null && onMouseLeave !== void 0 ? onMouseLeave : _onMouseLeave, onClick: (e) => {
|
|
57
|
+
return (react_1.default.createElement("a", { ...props, ref: ref, href: href, "data-testid": testId, onMouseDown: onMouseDown !== null && onMouseDown !== void 0 ? onMouseDown : _onMouseDown, onMouseEnter: onMouseEnter !== null && onMouseEnter !== void 0 ? onMouseEnter : _onMouseEnter, onMouseLeave: onMouseLeave !== null && onMouseLeave !== void 0 ? onMouseLeave : _onMouseLeave, "data-xstate-tree": true, onClick: (e) => {
|
|
58
58
|
var _a;
|
|
59
59
|
if (((_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e)) === false) {
|
|
60
60
|
return;
|
package/lib/testingUtilities.js
CHANGED
|
@@ -121,7 +121,7 @@ function buildTestRootComponent(machine, logger) {
|
|
|
121
121
|
(0, xstateTree_1.recursivelySend)(interpreter, event);
|
|
122
122
|
}
|
|
123
123
|
function changeHandler(ctx, oldCtx) {
|
|
124
|
-
logger("onChange: ",
|
|
124
|
+
logger("onChange: ", (0, utils_1.difference)(oldCtx, ctx));
|
|
125
125
|
onChangeEmitter.emit("changed", ctx);
|
|
126
126
|
}
|
|
127
127
|
function onEventHandler(e) {
|
package/lib/utils.js
CHANGED
|
@@ -35,90 +35,28 @@ function isLikelyPageLoad() {
|
|
|
35
35
|
return performance.now() < 5000;
|
|
36
36
|
}
|
|
37
37
|
exports.isLikelyPageLoad = isLikelyPageLoad;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* @param {Object} obj1 The original object
|
|
44
|
-
* @param {Object} obj2 The object to compare against it
|
|
45
|
-
* @return {Object} An object of differences between the two
|
|
46
|
-
*/
|
|
47
|
-
function difference(obj1, obj2) {
|
|
48
|
-
if (!obj2 || Object.prototype.toString.call(obj2) !== "[object Object]") {
|
|
49
|
-
return obj1;
|
|
50
|
-
}
|
|
51
|
-
const diffs = {};
|
|
52
|
-
let key;
|
|
53
|
-
/**
|
|
54
|
-
* Check if two arrays are equal
|
|
55
|
-
* @param {Array} arr1 The first array
|
|
56
|
-
* @param {Array} arr2 The second array
|
|
57
|
-
* @return {Boolean} If true, both arrays are equal
|
|
58
|
-
*/
|
|
59
|
-
const arraysMatch = function arraysMatch(arr1, arr2) {
|
|
60
|
-
if (arr1.length !== arr2.length)
|
|
61
|
-
return false;
|
|
62
|
-
for (let i = 0; i < arr1.length; i++) {
|
|
63
|
-
if (arr1[i] !== arr2[i])
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Compare two items and push non-matches to object
|
|
70
|
-
* @param {*} item1 The first item
|
|
71
|
-
* @param {*} item2 The second item
|
|
72
|
-
* @param {String} key The key in our object
|
|
73
|
-
*/
|
|
74
|
-
function compare(item1, item2, key) {
|
|
75
|
-
const type1 = Object.prototype.toString.call(item1);
|
|
76
|
-
const type2 = Object.prototype.toString.call(item2);
|
|
77
|
-
if (type2 === "[object Undefined]") {
|
|
78
|
-
diffs[key] = null;
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (type1 !== type2) {
|
|
82
|
-
diffs[key] = item2;
|
|
83
|
-
return;
|
|
38
|
+
function difference(a, b) {
|
|
39
|
+
const result = {};
|
|
40
|
+
for (const key in b) {
|
|
41
|
+
if (!a.hasOwnProperty(key)) {
|
|
42
|
+
result[key] = b[key];
|
|
84
43
|
}
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
diffs[key] = objDiff;
|
|
44
|
+
else if (Array.isArray(b[key]) && Array.isArray(a[key])) {
|
|
45
|
+
if (JSON.stringify(b[key]) !== JSON.stringify(a[key])) {
|
|
46
|
+
result[key] = b[key];
|
|
89
47
|
}
|
|
90
|
-
return;
|
|
91
48
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
49
|
+
else if (typeof b[key] === "object" && typeof a[key] === "object") {
|
|
50
|
+
const value = difference(a[key], b[key]);
|
|
51
|
+
if (Object.keys(value).length > 0) {
|
|
52
|
+
result[key] = value;
|
|
95
53
|
}
|
|
96
|
-
return;
|
|
97
54
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
diffs[key] = item2;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
if (item1 !== item2) {
|
|
105
|
-
diffs[key] = item2;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
for (key in obj1) {
|
|
110
|
-
if (obj1.hasOwnProperty(key)) {
|
|
111
|
-
compare(obj1[key], obj2[key], key);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
for (key in obj2) {
|
|
115
|
-
if (obj2.hasOwnProperty(key)) {
|
|
116
|
-
if (!obj1[key] && obj1[key] !== obj2[key]) {
|
|
117
|
-
diffs[key] = obj2[key];
|
|
118
|
-
}
|
|
55
|
+
else if (b[key] !== a[key]) {
|
|
56
|
+
result[key] = b[key];
|
|
119
57
|
}
|
|
120
58
|
}
|
|
121
|
-
return
|
|
59
|
+
return result;
|
|
122
60
|
}
|
|
123
61
|
exports.difference = difference;
|
|
124
62
|
/*
|
package/package.json
CHANGED