@arrai-innovations/reactive-helpers 8.3.3 → 8.5.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/README.md +9 -1
- package/package.json +1 -1
- package/tests/unit/utils/set.spec.js +14 -1
- package/use/cancellableIntent.js +3 -1
- package/use/objectInstance.js +6 -0
- package/utils/set.js +4 -0
package/README.md
CHANGED
|
@@ -447,7 +447,14 @@ We make use of the basic set operations provided as example on mdn:
|
|
|
447
447
|
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#implementing_basic_set_operations
|
|
448
448
|
|
|
449
449
|
```js
|
|
450
|
-
import {
|
|
450
|
+
import {
|
|
451
|
+
isSuperset,
|
|
452
|
+
union,
|
|
453
|
+
intersection,
|
|
454
|
+
symmetricDifference,
|
|
455
|
+
difference,
|
|
456
|
+
equals,
|
|
457
|
+
} from "@arrai-innovations/reactive-helpers";
|
|
451
458
|
|
|
452
459
|
isSuperset(new Set([1, 2, 3, 4]), new Set([1, 2, 3])); // true
|
|
453
460
|
union(new Set([1, 2, 3, 4]), new Set([1, 2, 3])); // Set { 1, 2, 3, 4 }
|
|
@@ -455,6 +462,7 @@ intersection(new Set([1, 2, 3, 4]), new Set([1, 2, 3])); // Set { 1, 2, 3 }
|
|
|
455
462
|
symmetricDifference(new Set([1, 2, 3, 4]), new Set([1, 2, 3, 5])); // Set { 4, 5 }
|
|
456
463
|
difference(new Set([1, 2, 3, 4]), new Set([1, 2, 3, 5])); // Set { 4 }
|
|
457
464
|
difference(new Set([1, 2, 3, 5]), new Set([1, 2, 3, 4])); // Set { 5 }
|
|
465
|
+
equals(new Set([1, 2, 3, 4]), new Set([1, 2, 3, 5])); // false
|
|
458
466
|
```
|
|
459
467
|
|
|
460
468
|
#### watches
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { difference, intersection, isSuperset, symmetricDifference, union } from "../../../utils/set.js";
|
|
1
|
+
import { difference, intersection, isSuperset, symmetricDifference, union, equals } from "../../../utils/set.js";
|
|
2
2
|
|
|
3
3
|
describe("utils/set", function () {
|
|
4
4
|
describe("isSuperset", function () {
|
|
@@ -57,6 +57,18 @@ describe("utils/set", function () {
|
|
|
57
57
|
expect(difference(set2, set1)).toEqual(new Set([5, 6]));
|
|
58
58
|
});
|
|
59
59
|
});
|
|
60
|
+
describe("equals", function () {
|
|
61
|
+
it("should return true if the two sets are equal", function () {
|
|
62
|
+
const set1 = new Set([1, 2, 3, 4]);
|
|
63
|
+
const set2 = new Set([1, 2, 3, 4]);
|
|
64
|
+
expect(equals(set1, set2)).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
it("should return false if the two sets are not equal", function () {
|
|
67
|
+
const set1 = new Set([1, 2, 3, 4]);
|
|
68
|
+
const set2 = new Set([1, 2, 3, 5]);
|
|
69
|
+
expect(equals(set1, set2)).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
60
72
|
it("should work as in the example for the readme", function () {
|
|
61
73
|
expect(isSuperset(new Set([1, 2, 3, 4]), new Set([1, 2, 3]))).toBe(true);
|
|
62
74
|
expect(union(new Set([1, 2, 3, 4]), new Set([1, 2, 3]))).toEqual(new Set([1, 2, 3, 4]));
|
|
@@ -64,5 +76,6 @@ describe("utils/set", function () {
|
|
|
64
76
|
expect(symmetricDifference(new Set([1, 2, 3, 4]), new Set([1, 2, 3, 5]))).toEqual(new Set([4, 5]));
|
|
65
77
|
expect(difference(new Set([1, 2, 3, 4]), new Set([1, 2, 3, 5]))).toEqual(new Set([4]));
|
|
66
78
|
expect(difference(new Set([1, 2, 3, 5]), new Set([1, 2, 3, 4]))).toEqual(new Set([5]));
|
|
79
|
+
expect(equals(new Set([1, 2, 3, 4]), new Set([1, 2, 3, 5]))).toBe(false);
|
|
67
80
|
});
|
|
68
81
|
});
|
package/use/cancellableIntent.js
CHANGED
|
@@ -87,6 +87,7 @@ export function useCancellableIntent({
|
|
|
87
87
|
|
|
88
88
|
const intentWatch = async () => {
|
|
89
89
|
let newWatchValues = deepUnref(Object.values(watchArguments));
|
|
90
|
+
const guardValues = deepUnref(Object.values(guardArguments));
|
|
90
91
|
if (isEqual(newWatchValues, previousWatchValues)) {
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
@@ -94,7 +95,7 @@ export function useCancellableIntent({
|
|
|
94
95
|
await cancel();
|
|
95
96
|
if (Object.values(previousWatchValues).every(identity)) {
|
|
96
97
|
// if any guards are true, delay the watch.
|
|
97
|
-
if (
|
|
98
|
+
if (guardValues && !isEmpty(guardValues) && guardValues.some(identity)) {
|
|
98
99
|
delayedWatch = doIntentWatch;
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
@@ -144,6 +145,7 @@ export function useCancellableIntent({
|
|
|
144
145
|
return {
|
|
145
146
|
state,
|
|
146
147
|
watchArguments: readonly(watchArguments),
|
|
148
|
+
guardArguments: readonly(guardArguments),
|
|
147
149
|
stop,
|
|
148
150
|
cancel,
|
|
149
151
|
};
|
package/use/objectInstance.js
CHANGED
|
@@ -222,6 +222,11 @@ export function useObjectInstance({ props, functions = {} }) {
|
|
|
222
222
|
state.error = null;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
function clear() {
|
|
226
|
+
clearError();
|
|
227
|
+
state.object = {};
|
|
228
|
+
}
|
|
229
|
+
|
|
225
230
|
return reactive({
|
|
226
231
|
state,
|
|
227
232
|
retrieve,
|
|
@@ -230,5 +235,6 @@ export function useObjectInstance({ props, functions = {} }) {
|
|
|
230
235
|
patch,
|
|
231
236
|
delete: deleteFn,
|
|
232
237
|
clearError,
|
|
238
|
+
clear,
|
|
233
239
|
});
|
|
234
240
|
}
|