@arrai-innovations/reactive-helpers 9.0.1 → 9.0.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/cancellableIntent.js +29 -11
- package/use/listInstance.js +12 -3
package/package.json
CHANGED
package/use/cancellableIntent.js
CHANGED
|
@@ -84,23 +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
|
-
if (isEqual(newWatchValues, previousWatchValues)) {
|
|
90
|
+
if (runningIntentWatch) {
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// if any guards are true, delay the watch.
|
|
99
|
-
if (guardValues && !isEmpty(guardValues) && guardValues.some(identity)) {
|
|
100
|
-
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)) {
|
|
101
98
|
return;
|
|
102
99
|
}
|
|
103
|
-
|
|
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;
|
|
104
122
|
}
|
|
105
123
|
};
|
|
106
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;
|
|
@@ -165,8 +173,9 @@ export function useListInstance({ props, functions = {}, keepOldPages = false })
|
|
|
165
173
|
.finally(() => {
|
|
166
174
|
state.loading = false;
|
|
167
175
|
returnPromiseResolve(resolveState);
|
|
176
|
+
promises.list = null;
|
|
168
177
|
});
|
|
169
|
-
return
|
|
178
|
+
return promises.list;
|
|
170
179
|
}
|
|
171
180
|
|
|
172
181
|
function addListObject(object) {
|