@arrai-innovations/reactive-helpers 2.1.0 → 2.1.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": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -152,6 +152,11 @@ export function useListInstance({ crudArgs, listArgs = {}, retrieveArgs = {} })
152
152
  return getFakeId(state.objects);
153
153
  }
154
154
 
155
+ function clearError() {
156
+ state.errored = false;
157
+ state.error = null;
158
+ }
159
+
155
160
  const es = effectScope();
156
161
 
157
162
  es.run(() => {
@@ -165,10 +170,11 @@ export function useListInstance({ crudArgs, listArgs = {}, retrieveArgs = {} })
165
170
  updateListObject,
166
171
  deleteListObject,
167
172
  clearList,
168
- effectScope: es,
173
+ clearError,
169
174
  getFakeId: ourGetFakeId,
170
175
  defaultPageCallback,
171
176
  pageCallback: defaultPageCallback,
177
+ effectScope: es,
172
178
  };
173
179
  return returnedObject;
174
180
  }
@@ -4,6 +4,7 @@ import { cloneDeep, isEmpty, isObject } from "lodash";
4
4
  import { assignReactiveObject } from "../utils/assignReactiveObject";
5
5
  import inspect from "browser-util-inspect";
6
6
  import { useCancellableIntent } from "../utils/cancellableIntent";
7
+ import loadingCombine from "../utils/loadingCombine";
7
8
 
8
9
  export class ListSubscriptionError extends Error {
9
10
  constructor(message) {
@@ -137,10 +138,16 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
137
138
  }
138
139
  }
139
140
 
141
+ function clearErrors() {
142
+ state.subscriptionErrored = false;
143
+ state.subscriptionError = null;
144
+ listInstance.clearErrors();
145
+ }
146
+
140
147
  const es = effectScope();
141
148
 
142
149
  es.run(() => {
143
- state.loading = computed(() => listInstance.state.loading || state.subscriptionLoading);
150
+ state.loading = computed(() => loadingCombine(listInstance.state.loading, state.subscriptionLoading));
144
151
  state.errored = computed(() => listInstance.state.errored || state.subscriptionErrored);
145
152
  state.error = computed(() => listInstance.state.error || state.subscriptionError);
146
153
 
@@ -190,6 +197,7 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
190
197
  subscribeIntent,
191
198
  subscribe: publicSubscribe,
192
199
  unsubscribe: publicUnsubscribe,
200
+ clearErrors,
193
201
  effectScope: es,
194
202
  };
195
203
  }
@@ -209,6 +209,11 @@ export function useObjectInstance({ crudArgs, id, retrieveArgs }) {
209
209
  });
210
210
  }
211
211
 
212
+ function clearError() {
213
+ state.errored = false;
214
+ state.error = null;
215
+ }
216
+
212
217
  const es = effectScope();
213
218
 
214
219
  // we could have effects? let's keep the interface to keep our options open to add without major changes.
@@ -221,6 +226,7 @@ export function useObjectInstance({ crudArgs, id, retrieveArgs }) {
221
226
  update,
222
227
  patch,
223
228
  delete: deleteFn,
229
+ clearError,
224
230
  effectScope: es,
225
231
  };
226
232
  }
@@ -3,6 +3,7 @@ import { computed, effectScope, reactive, toRef } from "vue";
3
3
  import { assignReactiveObject } from "../utils/assignReactiveObject";
4
4
  import { useObjectInstance } from "./objectInstance";
5
5
  import { useCancellableIntent } from "../utils/cancellableIntent";
6
+ import loadingCombine from "../utils/loadingCombine";
6
7
 
7
8
  export class ObjectSubscriptionError extends Error {
8
9
  constructor(message) {
@@ -146,10 +147,16 @@ export function useObjectSubscription({ objectInstance, crudArgs, id, retrieveAr
146
147
  return didUnsubscribe;
147
148
  }
148
149
 
150
+ function clearError() {
151
+ state.subscriptionErrored = false;
152
+ state.subscriptionError = null;
153
+ objectInstance.clearError();
154
+ }
155
+
149
156
  const es = effectScope();
150
157
 
151
158
  es.run(() => {
152
- state.loading = computed(() => objectInstance.state.loading || state.subscriptionLoading);
159
+ state.loading = computed(() => loadingCombine(objectInstance.state.loading, state.subscriptionLoading));
153
160
  state.errored = computed(() => objectInstance.state.errored || state.subscriptionErrored);
154
161
  state.error = computed(() => objectInstance.state.error || state.subscriptionError);
155
162
 
@@ -178,6 +185,7 @@ export function useObjectSubscription({ objectInstance, crudArgs, id, retrieveAr
178
185
  unsubscribe: publicUnsubscribe,
179
186
  updateFromSubscription,
180
187
  deleteFromSubscription,
188
+ clearError,
181
189
  effectScope: es,
182
190
  };
183
191
  }
@@ -0,0 +1,13 @@
1
+ export default function (...loadingStates) {
2
+ // loadingStates is an array of booleans or undefined
3
+ // if any true, return true
4
+ // if all undefined, return undefined
5
+ // otherwise return false (all false)
6
+ if (loadingStates.some((loadingState) => loadingState === true)) {
7
+ return true;
8
+ }
9
+ if (loadingStates.every((loadingState) => loadingState === undefined)) {
10
+ return undefined;
11
+ }
12
+ return false;
13
+ }