@arrai-innovations/reactive-helpers 9.0.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "9.0.1",
3
+ "version": "9.0.2",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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
- let newWatchValues = deepUnref(Object.values(watchArguments));
90
- if (isEqual(newWatchValues, previousWatchValues)) {
90
+ if (runningIntentWatch) {
91
91
  return;
92
92
  }
93
- previousWatchValues = newWatchValues;
94
- await cancel(); // this can take time so guards and watches can change!
95
- newWatchValues = deepUnref(Object.values(watchArguments));
96
- const guardValues = deepUnref(Object.values(guardArguments));
97
- if (Object.values(newWatchValues).every(identity)) {
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
- doIntentWatch();
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
 
@@ -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
- const returnPromise = new Promise((resolve) => (returnPromiseResolve = resolve));
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
- returnPromise.cancel = async () => {
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 returnPromise;
177
+ return promises.list;
170
178
  }
171
179
 
172
180
  function addListObject(object) {