@arrai-innovations/reactive-helpers 3.0.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/use/index.js +2 -0
- package/use/listCalculated.js +20 -1
- package/use/listRelated.js +17 -1
- package/use/listSubscription.js +1 -1
- package/use/object.js +1 -0
- package/use/objectCalculated.js +18 -1
- package/use/objectRelated.js +19 -2
- package/use/objectSubscription.js +2 -3
- package/use/watchesRunning.js +31 -0
- package/utils/index.js +0 -1
- /package/{utils → use}/cancellableIntent.js +0 -0
package/package.json
CHANGED
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/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,7 +1,7 @@
|
|
|
1
1
|
import inspect from "browser-util-inspect";
|
|
2
2
|
import { cloneDeep, isEmpty, isObject } from "lodash";
|
|
3
3
|
import { computed, effectScope, reactive, toRef } from "vue";
|
|
4
|
-
import { useCancellableIntent } from "
|
|
4
|
+
import { useCancellableIntent } from "./cancellableIntent";
|
|
5
5
|
import { loadingCombine } from "../utils/loadingCombine";
|
|
6
6
|
import { useListInstance } from "./listInstance";
|
|
7
7
|
|
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(() => {
|
|
@@ -109,6 +115,16 @@ export function useObjectCalculated({
|
|
|
109
115
|
}
|
|
110
116
|
);
|
|
111
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
|
+
|
|
112
128
|
onScopeDispose(() => {
|
|
113
129
|
for (const key in calculatedObjectEffectScopes) {
|
|
114
130
|
calculatedObjectEffectScopes[key].stop();
|
|
@@ -121,6 +137,7 @@ export function useObjectCalculated({
|
|
|
121
137
|
return {
|
|
122
138
|
state,
|
|
123
139
|
parentState,
|
|
140
|
+
watchesRunning,
|
|
124
141
|
effectScope: es,
|
|
125
142
|
};
|
|
126
143
|
}
|
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(() => {
|
|
@@ -114,15 +119,27 @@ export function useObjectRelated({
|
|
|
114
119
|
}
|
|
115
120
|
);
|
|
116
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
|
+
|
|
117
132
|
onScopeDispose(() => {
|
|
118
133
|
for (const key in relatedObjectEffectScopes) {
|
|
119
134
|
relatedObjectEffectScopes[key].stop();
|
|
120
135
|
}
|
|
121
136
|
});
|
|
122
137
|
});
|
|
138
|
+
|
|
123
139
|
return {
|
|
124
140
|
state,
|
|
125
141
|
parentState,
|
|
142
|
+
watchesRunning,
|
|
126
143
|
effectScope: es,
|
|
127
144
|
};
|
|
128
145
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { computed, effectScope, reactive, toRef } from "vue";
|
|
2
|
-
import { assignReactiveObject } from "../utils
|
|
3
|
-
import { useCancellableIntent } from "
|
|
4
|
-
import { loadingCombine } from "../utils/loadingCombine";
|
|
2
|
+
import { assignReactiveObject, loadingCombine } from "../utils";
|
|
3
|
+
import { useCancellableIntent } from "./cancellableIntent";
|
|
5
4
|
import { useObjectInstance } from "./objectInstance";
|
|
6
5
|
|
|
7
6
|
export class ObjectSubscriptionError extends Error {
|
|
@@ -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
|
+
}
|
package/utils/index.js
CHANGED
|
File without changes
|