@arrai-innovations/reactive-helpers 8.3.1 → 8.3.3
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/package.json +1 -1
- package/use/objectSubscription.js +8 -3
- package/utils/compact.js +23 -19
package/package.json
CHANGED
|
@@ -175,7 +175,7 @@ export function useObjectSubscription({
|
|
|
175
175
|
awaitableWithCancel: subscribe,
|
|
176
176
|
watchArguments: reactive({
|
|
177
177
|
intendToSubscribe: toRef(state, "intendToSubscribe"),
|
|
178
|
-
|
|
178
|
+
id: toRef(parentState, "id"),
|
|
179
179
|
retrieveArgs: toRef(parentState, "retrieveArgs"),
|
|
180
180
|
}),
|
|
181
181
|
clearActiveOnResolved: false,
|
|
@@ -184,10 +184,15 @@ export function useObjectSubscription({
|
|
|
184
184
|
retrieveIntent = useCancellableIntent({
|
|
185
185
|
awaitableWithCancel: objectInstance.retrieve,
|
|
186
186
|
watchArguments: reactive({
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
intendToRetrieve: toRef(state, "intendToRetrieve"),
|
|
188
|
+
id: toRef(parentState, "id"),
|
|
189
189
|
retrieveArgs: toRef(parentState, "retrieveArgs"),
|
|
190
190
|
}),
|
|
191
|
+
// delay triggering a retrieve until the last retrieve has finished/cancelled
|
|
192
|
+
// cancel can still be triggered
|
|
193
|
+
guardArguments: reactive({
|
|
194
|
+
loading: toRef(state, "loading"),
|
|
195
|
+
}),
|
|
191
196
|
});
|
|
192
197
|
});
|
|
193
198
|
|
package/utils/compact.js
CHANGED
|
@@ -4,12 +4,7 @@ const removeEmptyObjectsRecursive = (obj) => {
|
|
|
4
4
|
if (typeof obj !== "object" || obj === null) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
-
if
|
|
8
|
-
for (const item of obj) {
|
|
9
|
-
removeEmptyObjectsRecursive(item);
|
|
10
|
-
}
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
7
|
+
// we need to go deep first, so we so empty nested objects are removed before we check if the object is empty
|
|
13
8
|
for (const [key, value] of Object.entries(obj)) {
|
|
14
9
|
if (typeof value === "object" && value !== null) {
|
|
15
10
|
if (Object.keys(value).length === 0) {
|
|
@@ -19,6 +14,12 @@ const removeEmptyObjectsRecursive = (obj) => {
|
|
|
19
14
|
removeEmptyObjectsRecursive(value);
|
|
20
15
|
}
|
|
21
16
|
}
|
|
17
|
+
if (Array.isArray(obj)) {
|
|
18
|
+
for (const item of obj) {
|
|
19
|
+
removeEmptyObjectsRecursive(item);
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -33,6 +34,12 @@ const compactSparseArraysRecursive = (obj) => {
|
|
|
33
34
|
if (typeof obj !== "object" || obj === null) {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
37
|
+
// we need to go deep first, so we so empty nested arrays are removed before we check if the array is empty
|
|
38
|
+
for (const value of Object.values(obj)) {
|
|
39
|
+
if (typeof value === "object" && value !== null) {
|
|
40
|
+
compactSparseArraysRecursive(value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
36
43
|
if (Array.isArray(obj)) {
|
|
37
44
|
for (let i = 0; i < obj.length; i++) {
|
|
38
45
|
if (obj[i] === undefined) {
|
|
@@ -41,11 +48,6 @@ const compactSparseArraysRecursive = (obj) => {
|
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
|
-
for (const value of Object.values(obj)) {
|
|
45
|
-
if (typeof value === "object" && value !== null) {
|
|
46
|
-
compactSparseArraysRecursive(value);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -60,14 +62,8 @@ const removeEmptyObjectsAndCompactSparseArraysRecursive = (obj) => {
|
|
|
60
62
|
if (typeof obj !== "object" || obj === null) {
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (obj[i] === undefined || isEmpty(obj[i])) {
|
|
66
|
-
obj.splice(i, 1);
|
|
67
|
-
i--;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
65
|
+
// we need to go deep first, so we so empty properties of objects or items in arrays are removed
|
|
66
|
+
// before we check if the object or array is empty
|
|
71
67
|
for (const [key, value] of Object.entries(obj)) {
|
|
72
68
|
if (typeof value === "object" && value !== null) {
|
|
73
69
|
if (Object.keys(value).length === 0) {
|
|
@@ -77,6 +73,14 @@ const removeEmptyObjectsAndCompactSparseArraysRecursive = (obj) => {
|
|
|
77
73
|
removeEmptyObjectsAndCompactSparseArraysRecursive(value);
|
|
78
74
|
}
|
|
79
75
|
}
|
|
76
|
+
if (Array.isArray(obj)) {
|
|
77
|
+
for (let i = 0; i < obj.length; i++) {
|
|
78
|
+
if (obj[i] === undefined || isEmpty(obj[i])) {
|
|
79
|
+
obj.splice(i, 1);
|
|
80
|
+
i--;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
80
84
|
};
|
|
81
85
|
|
|
82
86
|
/**
|