@arrai-innovations/reactive-helpers 9.0.0 → 9.0.2
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/cancellableIntent.js +29 -10
- package/use/listInstance.js +11 -3
package/package.json
CHANGED
package/use/cancellableIntent.js
CHANGED
|
@@ -84,22 +84,41 @@ export function useCancellableIntent({
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
let delayedWatch = null;
|
|
87
|
+
let runningIntentWatch = null;
|
|
87
88
|
|
|
88
89
|
const intentWatch = async () => {
|
|
89
|
-
|
|
90
|
-
const guardValues = deepUnref(Object.values(guardArguments));
|
|
91
|
-
if (isEqual(newWatchValues, previousWatchValues)) {
|
|
90
|
+
if (runningIntentWatch) {
|
|
92
91
|
return;
|
|
93
92
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
delayedWatch = doIntentWatch;
|
|
93
|
+
runningIntentWatch = true;
|
|
94
|
+
// this locked section is to deal with multiple intentWatches running while waiting for cancel to resolve
|
|
95
|
+
try {
|
|
96
|
+
let newWatchValues = deepUnref(Object.values(watchArguments));
|
|
97
|
+
if (isEqual(newWatchValues, previousWatchValues)) {
|
|
100
98
|
return;
|
|
101
99
|
}
|
|
102
|
-
|
|
100
|
+
await cancel(); // this can take time so guards and watches can change!
|
|
101
|
+
newWatchValues = deepUnref(Object.values(watchArguments));
|
|
102
|
+
if (isEqual(newWatchValues, previousWatchValues)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
previousWatchValues = newWatchValues;
|
|
106
|
+
const guardValues = deepUnref(Object.values(guardArguments));
|
|
107
|
+
if (Object.values(newWatchValues).every(identity)) {
|
|
108
|
+
// if any guards are true, delay the watch.
|
|
109
|
+
if (guardValues && !isEmpty(guardValues) && guardValues.some(identity)) {
|
|
110
|
+
delayedWatch = doIntentWatch;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
doIntentWatch();
|
|
114
|
+
} else {
|
|
115
|
+
// if there already is a delayed watch, but the values have gone false, cancel it
|
|
116
|
+
if (delayedWatch) {
|
|
117
|
+
delayedWatch = null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} finally {
|
|
121
|
+
runningIntentWatch = false;
|
|
103
122
|
}
|
|
104
123
|
};
|
|
105
124
|
|
package/use/listInstance.js
CHANGED
|
@@ -128,13 +128,21 @@ export function useListInstance({ props, functions = {}, keepOldPages = false })
|
|
|
128
128
|
});
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
+
const promises = {
|
|
132
|
+
list: null,
|
|
133
|
+
};
|
|
134
|
+
|
|
131
135
|
function list() {
|
|
132
136
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
137
|
+
if (promises.list) {
|
|
138
|
+
// if a retrieve is already in progress, return the existing promise
|
|
139
|
+
return promises.list;
|
|
140
|
+
}
|
|
133
141
|
if (state.loading) {
|
|
134
142
|
return Promise.reject(new ListError("already loading."));
|
|
135
143
|
}
|
|
136
144
|
let returnPromiseResolve;
|
|
137
|
-
|
|
145
|
+
promises.list = new Promise((resolve) => (returnPromiseResolve = resolve));
|
|
138
146
|
state.loading = true;
|
|
139
147
|
state.errored = false;
|
|
140
148
|
state.error = null;
|
|
@@ -146,7 +154,7 @@ export function useListInstance({ props, functions = {}, keepOldPages = false })
|
|
|
146
154
|
});
|
|
147
155
|
let resolveState = false;
|
|
148
156
|
if (listPromise.cancel) {
|
|
149
|
-
|
|
157
|
+
promises.list.cancel = async () => {
|
|
150
158
|
let promise = listPromise.cancel();
|
|
151
159
|
if (promise) {
|
|
152
160
|
await promise;
|
|
@@ -166,7 +174,7 @@ export function useListInstance({ props, functions = {}, keepOldPages = false })
|
|
|
166
174
|
state.loading = false;
|
|
167
175
|
returnPromiseResolve(resolveState);
|
|
168
176
|
});
|
|
169
|
-
return
|
|
177
|
+
return promises.list;
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
function addListObject(object) {
|