@arrai-innovations/reactive-helpers 4.0.0 → 4.1.1

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": "4.0.0",
3
+ "version": "4.1.1",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "directories": {
package/use/list.js CHANGED
@@ -3,9 +3,10 @@ import { useListCalculated } from "./listCalculated";
3
3
  import { useListInstance } from "./listInstance";
4
4
  import { useListRelated } from "./listRelated";
5
5
  import { useListSubscription } from "./listSubscription";
6
+ import { usePagedListInstance } from "./paginatedListInstance";
6
7
 
7
8
  // the big brother of useObject, managing a chain of useList* instances.
8
- export const useList = ({ props, functions }) => {
9
+ export const useList = ({ props, functions, paged = false }) => {
9
10
  const managed = shallowReactive({
10
11
  listInstance: null,
11
12
  listSubscription: null,
@@ -14,7 +15,7 @@ export const useList = ({ props, functions }) => {
14
15
  });
15
16
  const es = effectScope();
16
17
 
17
- managed.listInstance = useListInstance({
18
+ managed.listInstance = (paged ? usePagedListInstance : useListInstance)({
18
19
  crudArgs: toRef(props, "crudArgs"),
19
20
  functions,
20
21
  retrieveArgs: toRef(props, "retrieveArgs"),
@@ -19,7 +19,7 @@ export function useListCalculated({
19
19
  parentState,
20
20
  calculatedObjectsRules,
21
21
  calculatedObjectsPropertyName = "calculatedObjects", // NOT REACTIVE
22
- passThroughPropertyNames = ["relatedObjects"], // NOT REACTIVE
22
+ passThroughPropertyNames = ["relatedObjects", "totalRecords", "totalPages", "perPage"], // NOT REACTIVE
23
23
  }) {
24
24
  const state = reactive({
25
25
  calculatedObjectsRules,
@@ -16,7 +16,7 @@ export function useListRelated({
16
16
  parentState,
17
17
  relatedObjectsRules,
18
18
  relatedObjectsPropertyName = "relatedObjects", // NOT REACTIVE
19
- passThroughPropertyNames = ["calculatedObjects"], // NOT REACTIVE
19
+ passThroughPropertyNames = ["calculatedObjects", "totalRecords", "totalPages", "perPage"], // NOT REACTIVE
20
20
  }) {
21
21
  const state = reactive({
22
22
  relatedObjectsRules: relatedObjectsRules,
@@ -28,13 +28,20 @@ export function useListSubscriptions(args, listInstances = {}) {
28
28
  return subscriptions;
29
29
  }
30
30
 
31
- export function useListSubscription({ listInstance, crudArgs, listArgs, retrieveArgs }) {
31
+ export function useListSubscription({
32
+ listInstance,
33
+ crudArgs,
34
+ listArgs,
35
+ retrieveArgs,
36
+ passThroughPropertyNames = ["totalRecords", "totalPages", "perPage"],
37
+ }) {
32
38
  if (!listInstance) {
33
39
  listInstance = useListInstance({ crudArgs, listArgs, retrieveArgs });
34
40
  }
35
41
  if (!listInstance.state.crud.subscribe) {
36
42
  listInstance.state.crud.subscribe = defaultCrud.subscribe;
37
43
  }
44
+ const parentState = listInstance.state;
38
45
 
39
46
  let subscribeIntent, listIntent;
40
47
  const state = reactive({
@@ -139,23 +146,26 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
139
146
  const es = effectScope();
140
147
 
141
148
  es.run(() => {
142
- state.loading = computed(() => loadingCombine(listInstance.state.loading, state.subscriptionLoading));
143
- state.errored = computed(() => listInstance.state.errored || state.subscriptionErrored);
144
- state.error = computed(() => listInstance.state.error || state.subscriptionError);
145
-
146
- state.retrieveArgs = computed(() => listInstance.state.retrieveArgs);
147
- state.listArgs = computed(() => listInstance.state.listArgs);
148
- state.objects = toRef(listInstance.state, "objects");
149
- state.order = toRef(listInstance.state, "order");
150
- state.objectsInOrder = toRef(listInstance.state, "objectsInOrder");
149
+ state.loading = computed(() => loadingCombine(parentState.loading, state.subscriptionLoading));
150
+ state.errored = computed(() => parentState.errored || state.subscriptionErrored);
151
+ state.error = computed(() => parentState.error || state.subscriptionError);
152
+
153
+ state.retrieveArgs = computed(() => parentState.retrieveArgs);
154
+ state.listArgs = computed(() => parentState.listArgs);
155
+ state.objects = toRef(parentState, "objects");
156
+ state.order = toRef(parentState, "order");
157
+ state.objectsInOrder = toRef(parentState, "objectsInOrder");
158
+ for (let key in passThroughPropertyNames) {
159
+ state[key] = toRef(parentState, key);
160
+ }
151
161
 
152
162
  subscribeIntent = useCancellableIntent({
153
163
  awaitableWithCancel: () => {
154
164
  // this function cannot be async, or the resulting promise will lose its .cancel() method
155
- const subscribePromise = listInstance.state.crud.subscribe({
156
- crudArgs: cloneDeep(listInstance.state.crud.args),
157
- listArgs: cloneDeep(listInstance.state.listArgs),
158
- retrieveArgs: cloneDeep(listInstance.state.retrieveArgs),
165
+ const subscribePromise = parentState.crud.subscribe({
166
+ crudArgs: cloneDeep(parentState.crud.args),
167
+ listArgs: cloneDeep(parentState.listArgs),
168
+ retrieveArgs: cloneDeep(parentState.retrieveArgs),
159
169
  subscriptionEventCallback,
160
170
  });
161
171
  // catching makes a new promise, we need to make sure the cancel method lives on.
@@ -169,8 +179,8 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
169
179
  },
170
180
  watchArguments: reactive({
171
181
  intendToSubscribe: toRef(state, "intendToSubscribe"),
172
- listArgs: toRef(listInstance.state, "listArgs"),
173
- retrieveArgs: toRef(listInstance.state, "retrieveArgs"),
182
+ listArgs: toRef(parentState, "listArgs"),
183
+ retrieveArgs: toRef(parentState, "retrieveArgs"),
174
184
  }),
175
185
  clearActiveOnResolved: false,
176
186
  });
@@ -184,8 +194,8 @@ export function useListSubscription({ listInstance, crudArgs, listArgs, retrieve
184
194
  },
185
195
  watchArguments: reactive({
186
196
  intendToList: toRef(state, "intendToList"),
187
- listArgs: toRef(listInstance.state, "listArgs"),
188
- retrieveArgs: toRef(listInstance.state, "retrieveArgs"),
197
+ listArgs: toRef(parentState, "listArgs"),
198
+ retrieveArgs: toRef(parentState, "retrieveArgs"),
189
199
  }),
190
200
  });
191
201
  });
@@ -1,7 +1,7 @@
1
1
  import { useListInstance } from "./listInstance";
2
2
 
3
- export function usePagedListInstance({ crudArgs, listArgs = {}, retrieveArgs = {} }) {
4
- const listInstance = useListInstance({ crudArgs, listArgs, retrieveArgs });
3
+ export function usePagedListInstance(useListInstanceArgs) {
4
+ const listInstance = useListInstance(useListInstanceArgs);
5
5
 
6
6
  listInstance.state.totalRecords = 0;
7
7
  listInstance.state.totalPages = 0;