@arrai-innovations/reactive-helpers 2.8.0 → 3.1.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/package.json +1 -1
- package/tests/unit/use/objectSubscription.spec.js +1 -1
- package/use/index.js +2 -0
- package/use/listCalculated.js +20 -1
- package/use/listInstance.js +2 -2
- package/use/listRelated.js +17 -1
- package/use/listSubscription.js +22 -21
- package/use/object.js +1 -0
- package/use/objectCalculated.js +30 -6
- package/use/objectInstance.js +3 -5
- package/use/objectRelated.js +31 -7
- package/use/objectSubscription.js +8 -18
- package/use/watchesRunning.js +31 -0
- package/utils/assignReactiveObject.js +23 -3
- package/utils/index.js +0 -1
- /package/{utils → use}/cancellableIntent.js +0 -0
package/package.json
CHANGED
|
@@ -601,7 +601,7 @@ describe("use/objectSubscription.js", function () {
|
|
|
601
601
|
},
|
|
602
602
|
});
|
|
603
603
|
objectSubscription.objectInstance.state.crud.retrieve = customCrudRetrieve;
|
|
604
|
-
objectSubscription.state.crud.subscribe = customCrudSubscribe;
|
|
604
|
+
objectSubscription.objectInstance.state.crud.subscribe = customCrudSubscribe;
|
|
605
605
|
|
|
606
606
|
const subscribePromise = objectSubscription.subscribe();
|
|
607
607
|
crudRetrieveResolve(crudRetrieveResolved);
|
package/use/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./cancellableIntent.js";
|
|
1
2
|
export * from "./listCalculated.js";
|
|
2
3
|
export * from "./listFilter.js";
|
|
3
4
|
export * from "./listInstance.js";
|
|
@@ -11,3 +12,4 @@ export * from "./objectRelated.js";
|
|
|
11
12
|
export * from "./objectSubscription.js";
|
|
12
13
|
export * from "./paginatedListInstance.js";
|
|
13
14
|
export * from "./search.js";
|
|
15
|
+
export * from "./watchesRunning.js";
|
package/use/listCalculated.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isEmpty } from "lodash";
|
|
2
2
|
import { computed, effectScope, onScopeDispose, reactive, toRef, watch } from "vue";
|
|
3
|
-
import { keyDiff } from "../utils";
|
|
3
|
+
import { keyDiff, loadingCombine } from "../utils";
|
|
4
|
+
import { useWatchesRunning } from "./watchesRunning";
|
|
4
5
|
|
|
5
6
|
export function useListCalculateds(instances, args) {
|
|
6
7
|
for (const [key, value] of Object.entries(args)) {
|
|
@@ -23,6 +24,8 @@ export function useListCalculated({
|
|
|
23
24
|
calculatedObjectsRules,
|
|
24
25
|
calculatedObjectsObjects: {},
|
|
25
26
|
objects: {},
|
|
27
|
+
parentStateObjectsWatchRunning: false,
|
|
28
|
+
calculatedObjectsWatchRunning: false,
|
|
26
29
|
});
|
|
27
30
|
const calculatedObjectsEffectScopes = {};
|
|
28
31
|
|
|
@@ -56,6 +59,7 @@ export function useListCalculated({
|
|
|
56
59
|
},
|
|
57
60
|
});
|
|
58
61
|
}
|
|
62
|
+
state.parentStateObjectsWatchRunning = false;
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
function calculatedObjectsWatch() {
|
|
@@ -98,9 +102,12 @@ export function useListCalculated({
|
|
|
98
102
|
}
|
|
99
103
|
calculatedObjectsEffectScopes[objectKey] = calculatedObjectsEffectScope;
|
|
100
104
|
}
|
|
105
|
+
state.calculatedObjectsWatchRunning = false;
|
|
101
106
|
parentStateObjectsWatch();
|
|
102
107
|
}
|
|
103
108
|
|
|
109
|
+
let watchesRunning = null;
|
|
110
|
+
|
|
104
111
|
const es = effectScope();
|
|
105
112
|
|
|
106
113
|
es.run(() => {
|
|
@@ -126,6 +133,16 @@ export function useListCalculated({
|
|
|
126
133
|
{ immediate: true }
|
|
127
134
|
);
|
|
128
135
|
|
|
136
|
+
watchesRunning = useWatchesRunning({
|
|
137
|
+
triggerRefs: [computed(() => (!isEmpty(state.calculatedObjectsRules) ? parentState.loading : false))],
|
|
138
|
+
watchSentinelRefs: [
|
|
139
|
+
toRef(state, "parentStateObjectsWatchRunning"),
|
|
140
|
+
toRef(state, "calculatedObjectsWatchRunning"),
|
|
141
|
+
],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
state.running = computed(() => loadingCombine(watchesRunning.state.running, parentState.running));
|
|
145
|
+
|
|
129
146
|
onScopeDispose(() => {
|
|
130
147
|
for (const objectKey of Object.keys(calculatedObjectsEffectScopes)) {
|
|
131
148
|
calculatedObjectsEffectScopes[objectKey].stop();
|
|
@@ -135,6 +152,8 @@ export function useListCalculated({
|
|
|
135
152
|
|
|
136
153
|
return {
|
|
137
154
|
state,
|
|
155
|
+
parentState,
|
|
156
|
+
watchesRunning,
|
|
138
157
|
effectScope: es,
|
|
139
158
|
};
|
|
140
159
|
}
|
package/use/listInstance.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import inspect from "browser-util-inspect";
|
|
2
2
|
import { cloneDeep } from "lodash";
|
|
3
3
|
import { computed, effectScope, reactive } from "vue";
|
|
4
|
-
import { assignReactiveObject } from "../utils/assignReactiveObject";
|
|
4
|
+
import { addOrUpdateReactiveObject, assignReactiveObject } from "../utils/assignReactiveObject";
|
|
5
5
|
import { getFakeId } from "../utils/getFakeId";
|
|
6
6
|
|
|
7
7
|
export class ListError extends Error {
|
|
@@ -80,7 +80,7 @@ export function useListInstance({ crudArgs, listArgs = {}, retrieveArgs = {} })
|
|
|
80
80
|
// prevent linking of all instances to the same default .args object
|
|
81
81
|
Object.assign(state.crud, cloneDeep(defaultCrud));
|
|
82
82
|
if (crudArgs) {
|
|
83
|
-
|
|
83
|
+
addOrUpdateReactiveObject(state.crud.args, crudArgs);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
const defaultPageCallback = (newObjects) => {
|
package/use/listRelated.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { get, isArray, isEmpty, isUndefined } from "lodash";
|
|
2
2
|
import { computed, effectScope, onScopeDispose, reactive, toRef, unref, watch } from "vue";
|
|
3
|
-
import { keyDiff } from "../utils
|
|
3
|
+
import { keyDiff, loadingCombine } from "../utils";
|
|
4
|
+
import { useWatchesRunning } from "./watchesRunning";
|
|
4
5
|
|
|
5
6
|
export function useListRelateds(instances, args) {
|
|
6
7
|
for (const [key, value] of Object.entries(args)) {
|
|
@@ -20,6 +21,8 @@ export function useListRelated({
|
|
|
20
21
|
relatedObjectsRules: relatedObjectsRules,
|
|
21
22
|
relatedObjectsObjects: {},
|
|
22
23
|
objects: {},
|
|
24
|
+
parentStateObjectsWatchRunning: false,
|
|
25
|
+
relatedObjectsWatchRunning: false,
|
|
23
26
|
});
|
|
24
27
|
const relatedObjectsEffectScopes = {};
|
|
25
28
|
|
|
@@ -128,6 +131,8 @@ export function useListRelated({
|
|
|
128
131
|
parentStateObjectsWatch();
|
|
129
132
|
}
|
|
130
133
|
|
|
134
|
+
let watchesRunning = null;
|
|
135
|
+
|
|
131
136
|
const es = effectScope();
|
|
132
137
|
|
|
133
138
|
es.run(() => {
|
|
@@ -150,6 +155,16 @@ export function useListRelated({
|
|
|
150
155
|
{ immediate: true }
|
|
151
156
|
);
|
|
152
157
|
|
|
158
|
+
watchesRunning = useWatchesRunning({
|
|
159
|
+
triggerRefs: [computed(() => (!isEmpty(state.relatedObjectsRules) ? parentState.loading : false))],
|
|
160
|
+
watchSentinelRefs: [
|
|
161
|
+
toRef(state, "parentStateObjectsWatchRunning"),
|
|
162
|
+
toRef(state, "relatedObjectsWatchRunning"),
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
state.running = computed(() => loadingCombine(watchesRunning.state.running, parentState.running));
|
|
167
|
+
|
|
153
168
|
onScopeDispose(() => {
|
|
154
169
|
for (const objectKey of Object.keys(relatedObjectsEffectScopes)) {
|
|
155
170
|
relatedObjectsEffectScopes[objectKey].stop();
|
|
@@ -159,6 +174,7 @@ export function useListRelated({
|
|
|
159
174
|
return {
|
|
160
175
|
state,
|
|
161
176
|
parentState,
|
|
177
|
+
watchesRunning,
|
|
162
178
|
effectScope: es,
|
|
163
179
|
};
|
|
164
180
|
}
|
package/use/listSubscription.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { computed, effectScope, reactive, toRef } from "vue";
|
|
2
|
-
import { useListInstance } from "./listInstance";
|
|
3
|
-
import { cloneDeep, isEmpty, isObject } from "lodash";
|
|
4
|
-
import { assignReactiveObject } from "../utils/assignReactiveObject";
|
|
5
1
|
import inspect from "browser-util-inspect";
|
|
6
|
-
import {
|
|
2
|
+
import { cloneDeep, isEmpty, isObject } from "lodash";
|
|
3
|
+
import { computed, effectScope, reactive, toRef } from "vue";
|
|
4
|
+
import { useCancellableIntent } from "./cancellableIntent";
|
|
7
5
|
import { loadingCombine } from "../utils/loadingCombine";
|
|
6
|
+
import { useListInstance } from "./listInstance";
|
|
8
7
|
|
|
9
8
|
export class ListSubscriptionError extends Error {
|
|
10
9
|
constructor(message) {
|
|
@@ -14,13 +13,11 @@ export class ListSubscriptionError extends Error {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
const defaultCrud = {
|
|
17
|
-
args: {},
|
|
18
16
|
subscribe: undefined,
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
export function setListSubscriptionCrud({ subscribe
|
|
19
|
+
export function setListSubscriptionCrud({ subscribe }) {
|
|
22
20
|
defaultCrud.subscribe = subscribe;
|
|
23
|
-
Object.assign(defaultCrud.args, args);
|
|
24
21
|
}
|
|
25
22
|
|
|
26
23
|
export function useListSubscriptions(args, listInstances = {}) {
|
|
@@ -35,23 +32,18 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
|
|
|
35
32
|
if (!listInstance) {
|
|
36
33
|
listInstance = useListInstance({ crudArgs, listArgs, retrieveArgs });
|
|
37
34
|
}
|
|
35
|
+
if (!listInstance.state.crud.subscribe) {
|
|
36
|
+
listInstance.state.crud.subscribe = defaultCrud.subscribe;
|
|
37
|
+
}
|
|
38
|
+
|
|
38
39
|
let subscribeIntent, listIntent;
|
|
39
40
|
const state = reactive({
|
|
40
|
-
crud: {
|
|
41
|
-
args: {},
|
|
42
|
-
subscribe: undefined,
|
|
43
|
-
},
|
|
44
41
|
subscriptionLoading: undefined,
|
|
45
42
|
subscriptionErrored: false,
|
|
46
43
|
subscriptionError: null,
|
|
47
44
|
intendToList: false,
|
|
48
45
|
intendToSubscribe: false,
|
|
49
46
|
});
|
|
50
|
-
// prevent linking of all instances to the same default .args object
|
|
51
|
-
Object.assign(state.crud, cloneDeep(defaultCrud));
|
|
52
|
-
if (crudArgs) {
|
|
53
|
-
assignReactiveObject(state.crud.args, crudArgs);
|
|
54
|
-
}
|
|
55
47
|
|
|
56
48
|
function publicSubscribe({ list = true } = {}) {
|
|
57
49
|
let didSubscribe = false;
|
|
@@ -160,8 +152,8 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
|
|
|
160
152
|
subscribeIntent = useCancellableIntent({
|
|
161
153
|
awaitableWithCancel: () => {
|
|
162
154
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
163
|
-
const subscribePromise = state.crud.subscribe({
|
|
164
|
-
crudArgs: cloneDeep(state.crud.args),
|
|
155
|
+
const subscribePromise = listInstance.state.crud.subscribe({
|
|
156
|
+
crudArgs: cloneDeep(listInstance.state.crud.args),
|
|
165
157
|
listArgs: cloneDeep(listInstance.state.listArgs),
|
|
166
158
|
retrieveArgs: cloneDeep(listInstance.state.retrieveArgs),
|
|
167
159
|
subscriptionEventCallback,
|
|
@@ -175,7 +167,11 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
|
|
|
175
167
|
catchPromise.cancel = subscribePromise.cancel;
|
|
176
168
|
return catchPromise;
|
|
177
169
|
},
|
|
178
|
-
watchArguments: [
|
|
170
|
+
watchArguments: [
|
|
171
|
+
toRef(state, "intendToSubscribe"),
|
|
172
|
+
toRef(listInstance.state, "listArgs"),
|
|
173
|
+
toRef(state, "retrieveArgs"),
|
|
174
|
+
],
|
|
179
175
|
clearActiveOnResolved: false,
|
|
180
176
|
});
|
|
181
177
|
|
|
@@ -186,7 +182,12 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
|
|
|
186
182
|
listInstance.clearList();
|
|
187
183
|
return listInstance.list();
|
|
188
184
|
},
|
|
189
|
-
watchArguments: [
|
|
185
|
+
watchArguments: [
|
|
186
|
+
toRef(state, "intendToList"),
|
|
187
|
+
toRef(listInstance.state, "listArgs"),
|
|
188
|
+
toRef(state, "retrieveArgs"),
|
|
189
|
+
],
|
|
190
|
+
nameOnLog: "listIntent",
|
|
190
191
|
});
|
|
191
192
|
});
|
|
192
193
|
|
package/use/object.js
CHANGED
package/use/objectCalculated.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { isEmpty } from "lodash";
|
|
1
2
|
import { computed, effectScope, onScopeDispose, reactive, toRef, watch } from "vue";
|
|
2
|
-
import { keyDiff } from "../utils";
|
|
3
|
+
import { keyDiff, loadingCombine } from "../utils";
|
|
4
|
+
import { useWatchesRunning } from "./watchesRunning";
|
|
3
5
|
|
|
4
6
|
export function useObjectCalculateds(instances, args) {
|
|
5
7
|
for (const [key, value] of Object.entries(args)) {
|
|
@@ -20,6 +22,8 @@ export function useObjectCalculated({
|
|
|
20
22
|
calculatedObjectRules,
|
|
21
23
|
calculatedObjectObjects: {},
|
|
22
24
|
object: {},
|
|
25
|
+
parentStateObjectWatchRunning: false,
|
|
26
|
+
calculatedObjectWatchRunning: false,
|
|
23
27
|
});
|
|
24
28
|
const calculatedObjectEffectScopes = {};
|
|
25
29
|
const calculatedObjectOriginalFunctions = {};
|
|
@@ -27,6 +31,8 @@ export function useObjectCalculated({
|
|
|
27
31
|
// don't change calculatedObjectPropertyName on us or it will break
|
|
28
32
|
const copn = calculatedObjectPropertyName + "";
|
|
29
33
|
|
|
34
|
+
let watchesRunning = null;
|
|
35
|
+
|
|
30
36
|
const es = effectScope();
|
|
31
37
|
|
|
32
38
|
es.run(() => {
|
|
@@ -67,12 +73,19 @@ export function useObjectCalculated({
|
|
|
67
73
|
state.deleted = toRef(parentState, "deleted");
|
|
68
74
|
|
|
69
75
|
watch(
|
|
70
|
-
[() => Object.keys(state.calculatedObjectRules)],
|
|
76
|
+
[() => state.calculatedObjectRules && Object.keys(state.calculatedObjectRules)],
|
|
71
77
|
() => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
78
|
+
let addedKeys = [],
|
|
79
|
+
removedKeys = [],
|
|
80
|
+
sameKeys = [];
|
|
81
|
+
if (!state.calculatedObjectRules) {
|
|
82
|
+
removedKeys = Object.keys(calculatedObjectOriginalFunctions);
|
|
83
|
+
} else {
|
|
84
|
+
({ addedKeys, removedKeys, sameKeys } = keyDiff(
|
|
85
|
+
Object.keys(state.calculatedObjectRules),
|
|
86
|
+
Object.keys(calculatedObjectOriginalFunctions)
|
|
87
|
+
));
|
|
88
|
+
}
|
|
76
89
|
for (const sameKey of sameKeys) {
|
|
77
90
|
if (calculatedObjectOriginalFunctions[sameKey] !== state.calculatedObjectRules[sameKey]) {
|
|
78
91
|
removedKeys.push(sameKey);
|
|
@@ -102,6 +115,16 @@ export function useObjectCalculated({
|
|
|
102
115
|
}
|
|
103
116
|
);
|
|
104
117
|
|
|
118
|
+
watchesRunning = useWatchesRunning({
|
|
119
|
+
triggerRefs: [computed(() => (!isEmpty(state.calculatedObjectRules) ? parentState.loading : false))],
|
|
120
|
+
watchSentinelRefs: [
|
|
121
|
+
toRef(state, "parentStateObjectWatchRunning"),
|
|
122
|
+
toRef(state, "calculatedObjectWatchRunning"),
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
state.running = computed(() => loadingCombine(watchesRunning.state.running, parentState.running));
|
|
127
|
+
|
|
105
128
|
onScopeDispose(() => {
|
|
106
129
|
for (const key in calculatedObjectEffectScopes) {
|
|
107
130
|
calculatedObjectEffectScopes[key].stop();
|
|
@@ -114,6 +137,7 @@ export function useObjectCalculated({
|
|
|
114
137
|
return {
|
|
115
138
|
state,
|
|
116
139
|
parentState,
|
|
140
|
+
watchesRunning,
|
|
117
141
|
effectScope: es,
|
|
118
142
|
};
|
|
119
143
|
}
|
package/use/objectInstance.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cloneDeep } from "lodash";
|
|
2
|
-
import { effectScope, reactive
|
|
3
|
-
import { assignReactiveObject } from "../utils/assignReactiveObject";
|
|
2
|
+
import { effectScope, reactive } from "vue";
|
|
3
|
+
import { addOrUpdateReactiveObject, assignReactiveObject } from "../utils/assignReactiveObject";
|
|
4
4
|
|
|
5
5
|
export class ObjectError extends Error {
|
|
6
6
|
constructor(message) {
|
|
@@ -56,9 +56,7 @@ export function useObjectInstance({ crudArgs, id, retrieveArgs }) {
|
|
|
56
56
|
// prevent linking of all instances to the same default .args object
|
|
57
57
|
Object.assign(state.crud, cloneDeep(defaultCrud));
|
|
58
58
|
if (crudArgs) {
|
|
59
|
-
|
|
60
|
-
// either way, we want a reactive or plain object. computed isn't going to work for this.
|
|
61
|
-
assignReactiveObject(state.crud.args, unref(crudArgs));
|
|
59
|
+
addOrUpdateReactiveObject(state.crud.args, crudArgs);
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
// due to retrieve being called by `useCancelleableIntent`, if called manually then by the watch,
|
package/use/objectRelated.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { get, isArray, isUndefined } from "lodash";
|
|
1
|
+
import { get, isArray, isEmpty, isUndefined } from "lodash";
|
|
2
2
|
import { computed, effectScope, onScopeDispose, reactive, toRef, unref, watch } from "vue";
|
|
3
|
-
import { keyDiff } from "../utils";
|
|
3
|
+
import { keyDiff, loadingCombine } from "../utils";
|
|
4
|
+
import { useWatchesRunning } from "./watchesRunning";
|
|
4
5
|
|
|
5
6
|
export function useObjectRelateds(instances, args) {
|
|
6
7
|
for (const [key, value] of Object.entries(args)) {
|
|
@@ -21,12 +22,16 @@ export function useObjectRelated({
|
|
|
21
22
|
relatedObjectRules,
|
|
22
23
|
relatedObjectObjects: {},
|
|
23
24
|
object: {},
|
|
25
|
+
parentStateObjectWatchRunning: false,
|
|
26
|
+
relatedObjectWatchRunning: false,
|
|
24
27
|
});
|
|
25
28
|
const relatedObjectEffectScopes = {};
|
|
26
29
|
|
|
27
30
|
// don't change relatedObjectPropertyName on us or it will break
|
|
28
31
|
const ropn = relatedObjectPropertyName + "";
|
|
29
32
|
|
|
33
|
+
let watchesRunning = null;
|
|
34
|
+
|
|
30
35
|
const es = effectScope();
|
|
31
36
|
|
|
32
37
|
es.run(() => {
|
|
@@ -67,12 +72,19 @@ export function useObjectRelated({
|
|
|
67
72
|
state.deleted = toRef(parentState, "deleted");
|
|
68
73
|
|
|
69
74
|
watch(
|
|
70
|
-
[() => Object.keys(state.relatedObjectRules)],
|
|
75
|
+
[() => state.relatedObjectRules && Object.keys(state.relatedObjectRules)],
|
|
71
76
|
() => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
let addedRuleKeys = [],
|
|
78
|
+
removedRuleKeys = [];
|
|
79
|
+
if (!state.relatedObjectRules) {
|
|
80
|
+
removedRuleKeys = Object.keys(state.relatedObjectObjects);
|
|
81
|
+
} else {
|
|
82
|
+
({ addedKeys: addedRuleKeys, removedKeys: removedRuleKeys } = keyDiff(
|
|
83
|
+
Object.keys(state.relatedObjectRules),
|
|
84
|
+
Object.keys(state.relatedObjectObjects)
|
|
85
|
+
));
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
for (const removedRuleKey of removedRuleKeys) {
|
|
77
89
|
delete state.relatedObjectObjects[removedRuleKey];
|
|
78
90
|
if (relatedObjectEffectScopes[removedRuleKey]) {
|
|
@@ -107,15 +119,27 @@ export function useObjectRelated({
|
|
|
107
119
|
}
|
|
108
120
|
);
|
|
109
121
|
|
|
122
|
+
watchesRunning = useWatchesRunning({
|
|
123
|
+
triggerRefs: [computed(() => (!isEmpty(state.relatedObjectRules) ? parentState.loading : false))],
|
|
124
|
+
watchSentinelRefs: [
|
|
125
|
+
toRef(state, "parentStateObjectWatchRunning"),
|
|
126
|
+
toRef(state, "relatedObjectWatchRunning"),
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
state.running = computed(() => loadingCombine(watchesRunning.state.running, parentState.running));
|
|
131
|
+
|
|
110
132
|
onScopeDispose(() => {
|
|
111
133
|
for (const key in relatedObjectEffectScopes) {
|
|
112
134
|
relatedObjectEffectScopes[key].stop();
|
|
113
135
|
}
|
|
114
136
|
});
|
|
115
137
|
});
|
|
138
|
+
|
|
116
139
|
return {
|
|
117
140
|
state,
|
|
118
141
|
parentState,
|
|
142
|
+
watchesRunning,
|
|
119
143
|
effectScope: es,
|
|
120
144
|
};
|
|
121
145
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { cloneDeep } from "lodash";
|
|
2
1
|
import { computed, effectScope, reactive, toRef } from "vue";
|
|
3
|
-
import { assignReactiveObject } from "../utils
|
|
4
|
-
import { useCancellableIntent } from "
|
|
5
|
-
import { loadingCombine } from "../utils/loadingCombine";
|
|
2
|
+
import { assignReactiveObject, loadingCombine } from "../utils";
|
|
3
|
+
import { useCancellableIntent } from "./cancellableIntent";
|
|
6
4
|
import { useObjectInstance } from "./objectInstance";
|
|
7
5
|
|
|
8
6
|
export class ObjectSubscriptionError extends Error {
|
|
@@ -13,13 +11,11 @@ export class ObjectSubscriptionError extends Error {
|
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
const defaultCrud = {
|
|
16
|
-
args: {},
|
|
17
14
|
subscribe: undefined,
|
|
18
15
|
};
|
|
19
16
|
|
|
20
|
-
export function setObjectSubscriptionCrud({ subscribe
|
|
17
|
+
export function setObjectSubscriptionCrud({ subscribe }) {
|
|
21
18
|
defaultCrud.subscribe = subscribe;
|
|
22
|
-
Object.assign(defaultCrud.args, args);
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
export function useObjectSubscriptions(subscriptionArgs) {
|
|
@@ -39,11 +35,10 @@ export function useObjectSubscription({ objectInstance, crudArgs, id, retrieveAr
|
|
|
39
35
|
if (!objectInstance) {
|
|
40
36
|
objectInstance = useObjectInstance({ crudArgs, id, retrieveArgs });
|
|
41
37
|
}
|
|
38
|
+
if (!objectInstance.state.crud.subscribe) {
|
|
39
|
+
objectInstance.state.crud.subscribe = defaultCrud.subscribe;
|
|
40
|
+
}
|
|
42
41
|
const state = reactive({
|
|
43
|
-
crud: {
|
|
44
|
-
args: {},
|
|
45
|
-
subscribe: undefined,
|
|
46
|
-
},
|
|
47
42
|
subscriptionLoading: undefined,
|
|
48
43
|
subscriptionErrored: false,
|
|
49
44
|
subscriptionError: null,
|
|
@@ -51,11 +46,6 @@ export function useObjectSubscription({ objectInstance, crudArgs, id, retrieveAr
|
|
|
51
46
|
intendToSubscribe: false,
|
|
52
47
|
intendToRetrieve: false,
|
|
53
48
|
});
|
|
54
|
-
// prevent linking of all instances to the same default .args object
|
|
55
|
-
Object.assign(state.crud, cloneDeep(defaultCrud));
|
|
56
|
-
if (crudArgs) {
|
|
57
|
-
assignReactiveObject(state.crud.args, crudArgs);
|
|
58
|
-
}
|
|
59
49
|
|
|
60
50
|
let subscribeIntent, retrieveIntent;
|
|
61
51
|
|
|
@@ -92,8 +82,8 @@ export function useObjectSubscription({ objectInstance, crudArgs, id, retrieveAr
|
|
|
92
82
|
state.subscriptionErrored = false;
|
|
93
83
|
state.subscriptionError = null;
|
|
94
84
|
let subscribePromise;
|
|
95
|
-
subscribePromise = state.crud.subscribe({
|
|
96
|
-
crudArgs: state.crud.args,
|
|
85
|
+
subscribePromise = objectInstance.state.crud.subscribe({
|
|
86
|
+
crudArgs: objectInstance.state.crud.args,
|
|
97
87
|
id: objectInstance.state.id,
|
|
98
88
|
retrieveArgs: state.retrieveArgs,
|
|
99
89
|
callback: (data, action) => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { computed, effectScope, reactive, unref, watch } from "vue";
|
|
2
|
+
import { loadingCombine } from "../utils";
|
|
3
|
+
|
|
4
|
+
export function useWatchesRunning({ triggerRefs, watchSentinelRefs }) {
|
|
5
|
+
const state = reactive({});
|
|
6
|
+
|
|
7
|
+
const es = effectScope();
|
|
8
|
+
|
|
9
|
+
es.run(() => {
|
|
10
|
+
watch(
|
|
11
|
+
triggerRefs,
|
|
12
|
+
(values) => {
|
|
13
|
+
if (values.every((value) => unref(value))) {
|
|
14
|
+
watchSentinelRefs.forEach((ref) => {
|
|
15
|
+
ref.value = true;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
immediate: true,
|
|
21
|
+
deep: true,
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
state.running = computed(() => loadingCombine(watchSentinelRefs.map((ref) => ref.value)));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
state,
|
|
29
|
+
effectScope: es,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import inspect from "browser-util-inspect";
|
|
2
|
+
import { isArray, isObject } from "lodash";
|
|
3
|
+
import { isReactive, isRef, toRef, unref } from "vue";
|
|
1
4
|
import { keyDiff } from "./keyDiff.js";
|
|
2
5
|
import { union } from "./set.js";
|
|
3
|
-
import { isReactive, toRef } from "vue";
|
|
4
|
-
import { isArray, isObject } from "lodash";
|
|
5
|
-
import inspect from "browser-util-inspect";
|
|
6
6
|
|
|
7
7
|
export class AssignReactiveObjectError extends Error {
|
|
8
8
|
constructor(message) {
|
|
@@ -20,6 +20,16 @@ function isArrayOrObject(key, value) {
|
|
|
20
20
|
export function addOrUpdateReactiveObject(target, source, exclude = [], addedKeys = null, sameKeys = null) {
|
|
21
21
|
isArrayOrObject("target", target);
|
|
22
22
|
isArrayOrObject("source", source);
|
|
23
|
+
if (isRef(target)) {
|
|
24
|
+
const unrefedTarget = unref(target);
|
|
25
|
+
isArrayOrObject("unrefedTarget", unrefedTarget);
|
|
26
|
+
target = unrefedTarget;
|
|
27
|
+
}
|
|
28
|
+
if (isRef(source)) {
|
|
29
|
+
const unrefedSource = unref(source);
|
|
30
|
+
isArrayOrObject("unrefedSource", unrefedSource);
|
|
31
|
+
source = unrefedSource;
|
|
32
|
+
}
|
|
23
33
|
if (!addedKeys && !sameKeys) {
|
|
24
34
|
({ addedKeys, sameKeys } = keyDiff(Object.keys(source) || [], Object.keys(target) || []));
|
|
25
35
|
}
|
|
@@ -42,6 +52,16 @@ export function assignReactiveObject(target, source, exclude = []) {
|
|
|
42
52
|
}
|
|
43
53
|
isArrayOrObject("target", target);
|
|
44
54
|
isArrayOrObject("source", source);
|
|
55
|
+
if (isRef(target)) {
|
|
56
|
+
const unrefedTarget = unref(target);
|
|
57
|
+
isArrayOrObject("unrefedTarget", unrefedTarget);
|
|
58
|
+
target = unrefedTarget;
|
|
59
|
+
}
|
|
60
|
+
if (isRef(source)) {
|
|
61
|
+
const unrefedSource = unref(source);
|
|
62
|
+
isArrayOrObject("unrefedSource", unrefedSource);
|
|
63
|
+
source = unrefedSource;
|
|
64
|
+
}
|
|
45
65
|
const targetIsArray = isArray(target);
|
|
46
66
|
const { addedKeys, sameKeys, removedKeys } = keyDiff(Object.keys(source) || [], Object.keys(target) || []);
|
|
47
67
|
if (targetIsArray) {
|
package/utils/index.js
CHANGED
|
File without changes
|