@arrai-innovations/reactive-helpers 3.2.1 → 4.0.0

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": "3.2.1",
3
+ "version": "4.0.0",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -54,6 +54,7 @@
54
54
  "lodash": "^4.17.21",
55
55
  "pinst": "^3.0.0",
56
56
  "vue": "^3.2.33",
57
+ "vue-deepunref": "^1.0.1",
57
58
  "vue-router": "^4.0.15"
58
59
  }
59
60
  }
@@ -0,0 +1,76 @@
1
+ import { nextTick } from "vue";
2
+ import { deepUnref } from "vue-deepunref";
3
+
4
+ describe("use/listCalculated", () => {
5
+ let useListInstance, useListCalculated;
6
+ beforeEach(async () => {
7
+ const listInstanceModule = await import("../../../use/listInstance");
8
+ useListInstance = listInstanceModule.useListInstance;
9
+ const listCalculatedModule = await import("../../../use/listCalculated");
10
+ useListCalculated = listCalculatedModule.useListCalculated;
11
+ });
12
+ it("should return a list of calculated items", async () => {
13
+ const mainListInstance = useListInstance({});
14
+ const calculatedListInstance = useListInstance({});
15
+ mainListInstance.addListObject({
16
+ id: "1",
17
+ name: "main",
18
+ calculated_items: ["2", "3"],
19
+ calculated_id: "4",
20
+ });
21
+ calculatedListInstance.addListObject({
22
+ id: "2",
23
+ name: "calculated1",
24
+ });
25
+ calculatedListInstance.addListObject({
26
+ id: "3",
27
+ name: "calculated2",
28
+ });
29
+ calculatedListInstance.addListObject({
30
+ id: "4",
31
+ name: "calculated3",
32
+ });
33
+ const listCalculated = useListCalculated({
34
+ parentState: mainListInstance.state,
35
+ calculatedObjectsRules: {
36
+ calculatedItems: (obj) => obj.calculated_items.map((x) => calculatedListInstance.state.objects[x]),
37
+ calculatedItem: (obj) => calculatedListInstance.state.objects[obj.calculated_id],
38
+ },
39
+ calculatedObjectsPropertyName: "myCalculatedObjects",
40
+ });
41
+ await nextTick();
42
+ // listCalculated.state.objects is doing proxy shenanigans
43
+ // in uses handler.has
44
+ expect("myCalculatedObjects" in listCalculated.state).toBe(true);
45
+ expect(!!listCalculated.state.myCalculatedObjects?.[1]).toBe(true);
46
+ expect("calculatedItems" in listCalculated.state.myCalculatedObjects[1]).toBe(true);
47
+ expect("calculatedItem" in listCalculated.state.myCalculatedObjects[1]).toBe(true);
48
+ // expect uses enumeration, which uses handler.ownKeys and handler.getOwnPropertyDescriptor
49
+ expect(deepUnref(listCalculated.state.objects)).toEqual({
50
+ 1: {
51
+ id: "1",
52
+ name: "main",
53
+ calculated_id: "4",
54
+ calculated_items: ["2", "3"],
55
+ },
56
+ });
57
+ expect(deepUnref(listCalculated.state.myCalculatedObjects)).toEqual({
58
+ 1: {
59
+ calculatedItems: [
60
+ {
61
+ id: "2",
62
+ name: "calculated1",
63
+ },
64
+ {
65
+ id: "3",
66
+ name: "calculated2",
67
+ },
68
+ ],
69
+ calculatedItem: {
70
+ id: "4",
71
+ name: "calculated3",
72
+ },
73
+ },
74
+ });
75
+ });
76
+ });
@@ -1,7 +1,7 @@
1
1
  import { nextTick, reactive, ref } from "vue";
2
- import { doAwaitNot } from "../../../utils/watches";
2
+ import { deepUnref } from "vue-deepunref";
3
3
  import { useListFilters, useListSort } from "../../../use";
4
- import { unrefAndToRawDeep } from "../../../utils";
4
+ import { doAwaitNot } from "../../../utils/watches";
5
5
 
6
6
  describe("use/listFilter", () => {
7
7
  let useListInstance, useListFilter, setDefaultSearchOptions;
@@ -318,10 +318,10 @@ describe("use/listFilter", () => {
318
318
 
319
319
  expect(listFilters.A.state.excludedValues).toEqual({ id: 1, name: "three" });
320
320
  expect(listFilters.B.state.allowedValues).toEqual({ id: 2, name: "four" });
321
- expect(unrefAndToRawDeep(listFilters.A.parentState)).toEqual(unrefAndToRawDeep(listFilterA.parentState));
322
- expect(unrefAndToRawDeep(listFilters.B.parentState)).toEqual(unrefAndToRawDeep(listFilterB.parentState));
323
- expect(unrefAndToRawDeep(listFilters.A.state)).toEqual(unrefAndToRawDeep(listFilterA.state));
324
- expect(unrefAndToRawDeep(listFilters.B.state)).toEqual(unrefAndToRawDeep(listFilterB.state));
321
+ expect(deepUnref(listFilters.A.parentState)).toEqual(deepUnref(listFilterA.parentState));
322
+ expect(deepUnref(listFilters.B.parentState)).toEqual(deepUnref(listFilterB.parentState));
323
+ expect(deepUnref(listFilters.A.state)).toEqual(deepUnref(listFilterA.state));
324
+ expect(deepUnref(listFilters.B.state)).toEqual(deepUnref(listFilterB.state));
325
325
  });
326
326
  });
327
327
  });
@@ -1,5 +1,5 @@
1
1
  import { nextTick } from "vue";
2
- import { unrefAndToRawDeep } from "../../../utils/unrefAndToRawDeep";
2
+ import { deepUnref } from "vue-deepunref";
3
3
 
4
4
  describe("use/listRelated", () => {
5
5
  let useListInstance, useListRelated;
@@ -47,31 +47,34 @@ describe("use/listRelated", () => {
47
47
  await nextTick();
48
48
  // listRelated.state.objects is doing proxy shenanigans
49
49
  // in uses handler.has
50
- expect("myRelatedObjects" in listRelated.state.objects[1]).toBe(true);
51
- expect("relatedItems" in listRelated.state.objects[1].myRelatedObjects).toBe(true);
52
- expect("relatedItem" in listRelated.state.objects[1].myRelatedObjects).toBe(true);
50
+ expect("myRelatedObjects" in listRelated.state).toBe(true);
51
+ expect(!!listRelated.state.myRelatedObjects?.[1]).toBe(true);
52
+ expect("relatedItems" in listRelated.state.myRelatedObjects[1]).toBe(true);
53
+ expect("relatedItem" in listRelated.state.myRelatedObjects[1]).toBe(true);
53
54
  // expect uses enumeration, which uses handler.ownKeys and handler.getOwnPropertyDescriptor
54
- expect(unrefAndToRawDeep(listRelated.state.objects)).toEqual({
55
+ expect(deepUnref(listRelated.state.objects)).toEqual({
55
56
  1: {
56
57
  id: "1",
57
58
  name: "main",
58
59
  related_id: "4",
59
60
  related_items: ["2", "3"],
60
- myRelatedObjects: {
61
- relatedItems: [
62
- {
63
- id: "2",
64
- name: "related1",
65
- },
66
- {
67
- id: "3",
68
- name: "related2",
69
- },
70
- ],
71
- relatedItem: {
72
- id: "4",
73
- name: "related3",
61
+ },
62
+ });
63
+ expect(deepUnref(listRelated.state.myRelatedObjects)).toEqual({
64
+ 1: {
65
+ relatedItems: [
66
+ {
67
+ id: "2",
68
+ name: "related1",
74
69
  },
70
+ {
71
+ id: "3",
72
+ name: "related2",
73
+ },
74
+ ],
75
+ relatedItem: {
76
+ id: "4",
77
+ name: "related3",
75
78
  },
76
79
  },
77
80
  });
@@ -1,5 +1,6 @@
1
1
  import { nextTick } from "vue";
2
- import { doAwaitTimeout, unrefAndToRawDeep } from "../../../utils";
2
+ import { deepUnref } from "vue-deepunref";
3
+ import { doAwaitTimeout } from "../../../utils";
3
4
 
4
5
  describe("use/useListSort", () => {
5
6
  let listInstance,
@@ -178,10 +179,10 @@ describe("use/useListSort", () => {
178
179
  },
179
180
  listInstances
180
181
  );
181
- expect(unrefAndToRawDeep(listSorts.A.parentState)).toEqual(unrefAndToRawDeep(listInstanceA.state));
182
- expect(unrefAndToRawDeep(listSorts.B.parentState)).toEqual(unrefAndToRawDeep(listInstanceB.state));
183
- expect(unrefAndToRawDeep(listSorts.A.state)).toEqual(unrefAndToRawDeep(listSortA.state));
184
- expect(unrefAndToRawDeep(listSorts.B.state)).toEqual(unrefAndToRawDeep(listSortB.state));
182
+ expect(deepUnref(listSorts.A.parentState)).toEqual(deepUnref(listInstanceA.state));
183
+ expect(deepUnref(listSorts.B.parentState)).toEqual(deepUnref(listInstanceB.state));
184
+ expect(deepUnref(listSorts.A.state)).toEqual(deepUnref(listSortA.state));
185
+ expect(deepUnref(listSorts.B.state)).toEqual(deepUnref(listSortB.state));
185
186
  });
186
187
  describe("useListSort/sortThrottleWait", () => {
187
188
  it("respects throttle time prior to triggering", async () => {
@@ -1,7 +1,7 @@
1
- import { nextTick, reactive } from "vue";
2
- import { inspect } from "util";
3
- import { doAwaitTimeout } from "../../../utils";
4
1
  import flushPromises from "flush-promises";
2
+ import { inspect } from "util";
3
+ import { nextTick, reactive } from "vue";
4
+ import { doAwaitNot, doAwaitTimeout } from "../../../utils";
5
5
  import { CancellableResolvable } from "../crudPromise";
6
6
  import { poll } from "../poll";
7
7
 
@@ -512,8 +512,12 @@ describe("use/listSubscription.spec.js", function () {
512
512
  listArgs.user = 2;
513
513
  retrieveArgs.fields = ["name"];
514
514
  await nextTick();
515
- await flushPromises();
516
- await doAwaitTimeout(1500);
515
+ await crudSubscribeResolvable[1].resolve();
516
+ await crudListResolvable[1].resolve();
517
+ await doAwaitNot({
518
+ obj: listSubscription.listIntent.state,
519
+ prop: "resolving",
520
+ });
517
521
  expect(crudSubscribeResolvable[0].promise.cancel).toHaveBeenCalledWith();
518
522
  expect(crudSubscribeResolvable[0].promise.cancel).toHaveBeenCalledTimes(1);
519
523
  expect(crudSubscribe).toHaveBeenCalledWith({
@@ -1,9 +1,10 @@
1
- import { effectScope, isReactive, isRef, onScopeDispose, reactive, unref, watch } from "vue";
2
- import { cloneDeep, isEqual } from "lodash";
1
+ import { identity, isEqual } from "lodash";
2
+ import { effectScope, nextTick, onScopeDispose, reactive, readonly, watch } from "vue";
3
+ import { deepUnref } from "vue-deepunref";
3
4
 
4
5
  /*
5
6
  * Calls your awaitable function with the arguments you pass in, when the watch arguments change and are all truthy.
6
- * Watch arguments can be an array or an object.
7
+ * Watch arguments should be a reactive object.
7
8
  * If the promise is not resolved before the watch arguments change again, the previous promise is cancelled.
8
9
  */
9
10
  export function useCancellableIntent({ awaitableWithCancel, watchArguments = {}, clearActiveOnResolved = true }) {
@@ -15,11 +16,12 @@ export function useCancellableIntent({ awaitableWithCancel, watchArguments = {},
15
16
  }
16
17
  const state = reactive({
17
18
  active: undefined,
19
+ resolving: undefined,
18
20
  errored: false,
19
21
  error: null,
20
22
  clearActiveOnResolved,
21
23
  });
22
- let previousWatchArguments = null,
24
+ let previousWatchValues = null,
23
25
  cancelFunction = null;
24
26
 
25
27
  const es = effectScope();
@@ -32,6 +34,7 @@ export function useCancellableIntent({ awaitableWithCancel, watchArguments = {},
32
34
  async function cancel() {
33
35
  if (cancelFunction) {
34
36
  state.active = false;
37
+ state.resolving = false;
35
38
  const cancelPromise = cancelFunction().catch(console.error);
36
39
  cancelFunction = null;
37
40
  return cancelPromise;
@@ -39,54 +42,58 @@ export function useCancellableIntent({ awaitableWithCancel, watchArguments = {},
39
42
  return false;
40
43
  }
41
44
 
42
- es.run(() => {
43
- watch(
44
- isReactive(watchArguments) || isRef(watchArguments) ? watchArguments : Object.values(watchArguments),
45
- () => {
46
- let newArguments = cloneDeep(watchArguments.map((arg) => unref(arg)));
47
- if (isEqual(unref(watchArguments), previousWatchArguments)) {
48
- return;
49
- }
50
- previousWatchArguments = newArguments;
51
- cancel().catch(console.error);
52
- if (Object.values(previousWatchArguments).every((v) => unref(v))) {
53
- state.errored = false;
54
- state.error = null;
55
- let awaitablePromise = awaitableWithCancel();
56
- state.active = true;
57
- if (awaitablePromise.cancel) {
58
- cancelFunction = async () => {
59
- state.active = false;
60
- cancelFunction = null;
61
- return awaitablePromise.cancel();
62
- };
63
- }
64
- awaitablePromise
65
- .then(() => {
66
- if (state.clearActiveOnResolved) {
67
- cancelFunction = null;
68
- state.active = false;
69
- }
70
- })
71
- .catch(async (err) => {
72
- await cancel();
73
- console.error(err);
74
- state.errored = true;
75
- state.error = err;
76
- throw err;
77
- });
78
- }
79
- },
80
- {
81
- deep: true,
82
- immediate: true,
45
+ const watchFn = () => {
46
+ let newWatchValues = deepUnref(Object.values(watchArguments));
47
+ if (isEqual(newWatchValues, previousWatchValues)) {
48
+ return;
49
+ }
50
+ previousWatchValues = newWatchValues;
51
+ cancel().catch(console.error);
52
+ if (Object.values(previousWatchValues).every(identity)) {
53
+ state.errored = false;
54
+ state.error = null;
55
+ let awaitablePromise = awaitableWithCancel();
56
+ state.active = true;
57
+ state.resolving = true;
58
+ if (awaitablePromise.cancel) {
59
+ cancelFunction = async () => {
60
+ state.active = false;
61
+ state.resolving = false;
62
+ cancelFunction = null;
63
+ return awaitablePromise.cancel();
64
+ };
83
65
  }
84
- );
66
+ awaitablePromise
67
+ .then(() => {
68
+ state.resolving = false;
69
+ if (state.clearActiveOnResolved) {
70
+ cancelFunction = null;
71
+ state.active = false;
72
+ }
73
+ })
74
+ .catch(async (err) => {
75
+ await cancel();
76
+ console.error(err);
77
+ state.errored = true;
78
+ state.error = err;
79
+ throw err;
80
+ });
81
+ }
82
+ };
83
+
84
+ es.run(() => {
85
+ watch(() => Object.values(watchArguments), watchFn, {
86
+ // this can't be immediate because subscribe wants to look at our state, which won't exist yet.
87
+ deep: true,
88
+ });
89
+
90
+ nextTick().then(watchFn);
85
91
 
86
92
  onScopeDispose(cancel);
87
93
  });
88
94
  return {
89
95
  state,
96
+ watchArguments: readonly(watchArguments),
90
97
  stop,
91
98
  cancel,
92
99
  };
package/use/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./cancellableIntent.js";
2
+ export * from "./list.js";
2
3
  export * from "./listCalculated.js";
3
4
  export * from "./listFilter.js";
4
5
  export * from "./listInstance.js";
package/use/list.js ADDED
@@ -0,0 +1,112 @@
1
+ import { effectScope, reactive, shallowReactive, shallowReadonly, toRef, watch } from "vue";
2
+ import { useListCalculated } from "./listCalculated";
3
+ import { useListInstance } from "./listInstance";
4
+ import { useListRelated } from "./listRelated";
5
+ import { useListSubscription } from "./listSubscription";
6
+
7
+ // the big brother of useObject, managing a chain of useList* instances.
8
+ export const useList = ({ props, functions }) => {
9
+ const managed = shallowReactive({
10
+ listInstance: null,
11
+ listSubscription: null,
12
+ listRelated: null,
13
+ listCalculated: null,
14
+ });
15
+ const es = effectScope();
16
+
17
+ managed.listInstance = useListInstance({
18
+ crudArgs: toRef(props, "crudArgs"),
19
+ functions,
20
+ retrieveArgs: toRef(props, "retrieveArgs"),
21
+ listArgs: toRef(props, "listArgs"),
22
+ });
23
+
24
+ const intentPropsWatch = () => {
25
+ es.run(() => {
26
+ let nextState = managed.listInstance?.state;
27
+ // true or false, having a key is intent to use
28
+ const hasIntendToList = "intendToList" in props;
29
+ if (hasIntendToList && !managed.listSubscription) {
30
+ managed.listSubscription = useListSubscription({
31
+ listInstance: managed.listInstance,
32
+ });
33
+ managed.listSubscription.state.intendToList = toRef(props, "intendToList");
34
+ } else if (!hasIntendToList && managed.listSubscription) {
35
+ managed.listSubscription.effectScope.stop();
36
+ managed.listSubscription = null;
37
+ }
38
+ const hasRelatedObjectRules = "relatedObjectsRules" in props;
39
+ if (hasRelatedObjectRules && !managed.listRelated) {
40
+ nextState = managed.listSubscription?.state || nextState;
41
+ managed.listRelated = useListRelated({
42
+ parentState: nextState,
43
+ relatedObjectsRules: toRef(props, "relatedObjectsRules"),
44
+ });
45
+ } else if (!hasRelatedObjectRules && managed.listRelated) {
46
+ managed.listRelated.effectScope.stop();
47
+ managed.listRelated = null;
48
+ }
49
+ const hasCalculatedObjectRules = "calculatedObjectsRules" in props;
50
+ if (hasCalculatedObjectRules && !managed.listCalculated) {
51
+ nextState = managed.listRelated?.state || nextState;
52
+ managed.listCalculated = useListCalculated({
53
+ parentState: nextState,
54
+ calculatedObjectsRules: toRef(props, "calculatedObjectsRules"),
55
+ });
56
+ } else if (!hasCalculatedObjectRules && managed.listCalculated) {
57
+ managed.listCalculated.effectScope.stop();
58
+ managed.listCalculated = null;
59
+ }
60
+ });
61
+ };
62
+
63
+ const exposedState = reactive({});
64
+
65
+ es.run(() => {
66
+ watch(
67
+ [
68
+ //
69
+ toRef(props, "intendToList"),
70
+ toRef(props, "relatedObjectsRules"),
71
+ toRef(props, "calculatedObjectsRules"),
72
+ ],
73
+ intentPropsWatch,
74
+ { immediate: true }
75
+ );
76
+ const propertiesToRelay = [
77
+ "loading",
78
+ "error",
79
+ "errored",
80
+ "objects",
81
+ "order",
82
+ "objectsInOrder",
83
+ "running",
84
+ "relatedObjects",
85
+ "calculatedObjects",
86
+ ];
87
+ watch(
88
+ () =>
89
+ managed.listCalculated?.state ||
90
+ managed.listRelated?.state ||
91
+ managed.listSubscription?.state ||
92
+ managed.listInstance?.state,
93
+ (newState, oldState) => {
94
+ if (newState !== oldState && newState) {
95
+ propertiesToRelay.forEach((x) => {
96
+ exposedState[x] = toRef(newState, x);
97
+ });
98
+ }
99
+ },
100
+ {
101
+ immediate: true,
102
+ }
103
+ );
104
+ });
105
+
106
+ return {
107
+ // we manage the keys on both of these, so hands off the root.
108
+ managed: shallowReadonly(managed),
109
+ state: shallowReadonly(exposedState),
110
+ effectScope: es,
111
+ };
112
+ };
@@ -19,11 +19,11 @@ export function useListCalculated({
19
19
  parentState,
20
20
  calculatedObjectsRules,
21
21
  calculatedObjectsPropertyName = "calculatedObjects", // NOT REACTIVE
22
+ passThroughPropertyNames = ["relatedObjects"], // NOT REACTIVE
22
23
  }) {
23
24
  const state = reactive({
24
25
  calculatedObjectsRules,
25
26
  calculatedObjectsObjects: {},
26
- objects: {},
27
27
  parentStateObjectsWatchRunning: false,
28
28
  calculatedObjectsWatchRunning: false,
29
29
  });
@@ -39,7 +39,6 @@ export function useListCalculated({
39
39
  );
40
40
  for (const removedKey of removedKeys) {
41
41
  delete state.calculatedObjectsObjects[removedKey];
42
- delete state.objects[removedKey];
43
42
  if (calculatedObjectsEffectScopes[removedKey]) {
44
43
  calculatedObjectsEffectScopes[removedKey].stop();
45
44
  delete calculatedObjectsEffectScopes[removedKey];
@@ -47,63 +46,46 @@ export function useListCalculated({
47
46
  }
48
47
  for (const addedKey of addedKeys) {
49
48
  state.calculatedObjectsObjects[addedKey] = {};
50
- state.objects[addedKey] = new Proxy(parentState.objects[addedKey], {
51
- get(target, prop, receiver) {
52
- if (prop === copn) {
53
- return state.calculatedObjectsObjects[addedKey];
54
- }
55
- return Reflect.get(target, prop, receiver);
56
- },
57
- ownKeys(target) {
58
- return Reflect.ownKeys(target).concat(copn);
59
- },
60
- });
61
49
  }
62
50
  state.parentStateObjectsWatchRunning = false;
63
51
  }
64
52
 
65
53
  function calculatedObjectsWatch() {
66
- if (state.calculatedObjectsRules === false) {
67
- return;
68
- }
69
- const calculatedObjectsRulesIsEmpty = isEmpty(state.calculatedObjectsRules);
54
+ const calculatedObjectsRulesIsEmpty = !state.calculatedObjectsRules || isEmpty(state.calculatedObjectsRules);
70
55
  for (const objectKey of Object.keys(state.calculatedObjectsObjects)) {
71
- const calculatedObjectsEffectScope = effectScope();
72
- calculatedObjectsEffectScope.run(() => {
73
- const calculatedObjectsObject = state.calculatedObjectsObjects[objectKey];
74
- const originalObject = parentState.objects[objectKey];
75
- if (!calculatedObjectsObject[copn]) {
76
- calculatedObjectsObject[copn] = {};
77
- }
78
- let removedRuleKeys, addedRuleKeys;
79
- if (!calculatedObjectsRulesIsEmpty) {
80
- ({ removedKeys: removedRuleKeys, addedKeys: addedRuleKeys } = keyDiff(
81
- Object.keys(state.calculatedObjectsRules),
82
- Object.keys(calculatedObjectsObject[copn])
83
- ));
84
- } else {
85
- if (isEmpty(calculatedObjectsObject[copn])) {
86
- return;
87
- }
88
- removedRuleKeys = Object.keys(calculatedObjectsObject[copn]);
89
- addedRuleKeys = [];
90
- }
91
- for (const removedRuleKey of removedRuleKeys) {
92
- delete calculatedObjectsObject[copn][removedRuleKey];
56
+ if (!calculatedObjectsEffectScopes[objectKey]) {
57
+ calculatedObjectsEffectScopes[objectKey] = effectScope();
58
+ }
59
+ const originalObject = parentState.objects[objectKey];
60
+ if (!state.calculatedObjectsObjects[objectKey]) {
61
+ state.calculatedObjectsObjects[objectKey] = {};
62
+ }
63
+ const calculatedObjectsObject = state.calculatedObjectsObjects[objectKey];
64
+ let removedRuleKeys, addedRuleKeys;
65
+ if (!calculatedObjectsRulesIsEmpty) {
66
+ ({ removedKeys: removedRuleKeys, addedKeys: addedRuleKeys } = keyDiff(
67
+ Object.keys(state.calculatedObjectsRules),
68
+ Object.keys(calculatedObjectsObject)
69
+ ));
70
+ } else {
71
+ if (isEmpty(calculatedObjectsObject)) {
72
+ return;
93
73
  }
74
+ removedRuleKeys = Object.keys(calculatedObjectsObject);
75
+ addedRuleKeys = [];
76
+ }
77
+ for (const removedRuleKey of removedRuleKeys) {
78
+ delete calculatedObjectsObject[removedRuleKey];
79
+ }
80
+ calculatedObjectsEffectScopes[objectKey].run(() => {
94
81
  for (const addedRuleKey of addedRuleKeys) {
95
- calculatedObjectsObject[copn][addedRuleKey] = computed(() => {
82
+ calculatedObjectsObject[addedRuleKey] = computed(() => {
96
83
  return state.calculatedObjectsRules?.[addedRuleKey]?.(originalObject);
97
84
  });
98
85
  }
99
86
  });
100
- if (calculatedObjectsEffectScopes[objectKey]) {
101
- calculatedObjectsEffectScopes[objectKey].stop();
102
- }
103
- calculatedObjectsEffectScopes[objectKey] = calculatedObjectsEffectScope;
104
87
  }
105
88
  state.calculatedObjectsWatchRunning = false;
106
- parentStateObjectsWatch();
107
89
  }
108
90
 
109
91
  let watchesRunning = null;
@@ -118,7 +100,12 @@ export function useListCalculated({
118
100
  state.retrieveArgs = toRef(parentState, "retrieveArgs");
119
101
  state.listArgs = toRef(parentState, "listArgs");
120
102
  state.order = toRef(parentState, "order");
121
- state.objectsInOrder = computed(() => state.order.map((id) => state.objects[id]));
103
+ state.objects = toRef(parentState, "objects");
104
+ state.objectsInOrder = toRef(parentState, "objectsInOrder");
105
+ state[copn] = toRef(state, "calculatedObjectsObjects");
106
+ for (let key in passThroughPropertyNames) {
107
+ state[key] = toRef(parentState, key);
108
+ }
122
109
 
123
110
  watch(() => Object.keys(parentState.objects), parentStateObjectsWatch, { immediate: true });
124
111
  watch(
@@ -134,7 +121,11 @@ export function useListCalculated({
134
121
  );
135
122
 
136
123
  watchesRunning = useWatchesRunning({
137
- triggerRefs: [computed(() => (!isEmpty(state.calculatedObjectsRules) ? parentState.loading : false))],
124
+ triggerRefs: [
125
+ computed(() =>
126
+ state.calculatedObjectsRules && !isEmpty(state.calculatedObjectsRules) ? parentState.loading : false
127
+ ),
128
+ ],
138
129
  watchSentinelRefs: [
139
130
  toRef(state, "parentStateObjectsWatchRunning"),
140
131
  toRef(state, "calculatedObjectsWatchRunning"),
@@ -1,5 +1,6 @@
1
1
  import inspect from "browser-util-inspect";
2
2
  import { cloneDeep } from "lodash";
3
+ import { isFunction } from "lodash";
3
4
  import { computed, effectScope, reactive } from "vue";
4
5
  import { addOrUpdateReactiveObject, assignReactiveObject } from "../utils/assignReactiveObject";
5
6
  import { getFakeId } from "../utils/getFakeId";
@@ -30,7 +31,7 @@ export function useListInstances(listInstanceArgs) {
30
31
  return instances;
31
32
  }
32
33
 
33
- export function useListInstance({ crudArgs, listArgs = {}, retrieveArgs = {} }) {
34
+ export function useListInstance({ crudArgs, listArgs = {}, retrieveArgs = {}, functions = {} }) {
34
35
  // ### touching the _objectsMap or _objectsProxy directly will not trigger reactivity ###
35
36
  const _objectsMap = new Map();
36
37
  // ### touching the _objectsMap or _objectsProxy directly will not trigger reactivity ###
@@ -82,6 +83,13 @@ export function useListInstance({ crudArgs, listArgs = {}, retrieveArgs = {} })
82
83
  if (crudArgs) {
83
84
  addOrUpdateReactiveObject(state.crud.args, crudArgs);
84
85
  }
86
+ for (const [key, value] of Object.entries(functions)) {
87
+ if (isFunction(value) && key in state.crud) {
88
+ state.crud[key] = value;
89
+ } else {
90
+ throw ListError(`Invalid function "${key}" for useListInstance: invalid key or not a function.`);
91
+ }
92
+ }
85
93
 
86
94
  const defaultPageCallback = (newObjects) => {
87
95
  newObjects.forEach((newObject) => {