@arrai-innovations/reactive-helpers 1.1.0 → 1.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": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -296,7 +296,7 @@ describe("use/listFilter", () => {
296
296
  name: "four",
297
297
  },
298
298
  });
299
- const args = {
299
+ const listFilterArgs = {
300
300
  A: {
301
301
  excludedValues: {
302
302
  id: 1,
@@ -310,21 +310,16 @@ describe("use/listFilter", () => {
310
310
  },
311
311
  },
312
312
  };
313
- const listInstanceModule = await import("../../../use/listInstance");
314
- const listInstances = listInstanceModule.useListInstances({
315
- A: {
316
- listInstanceA,
317
- },
318
- B: {
319
- listInstanceB,
320
- },
321
- });
322
- const listFilters = useListFilters(args, listInstances);
313
+ const listInstances = {
314
+ A: listInstanceA,
315
+ B: listInstanceB,
316
+ };
317
+ const listFilters = useListFilters(listFilterArgs, listInstances);
323
318
 
324
319
  expect(listFilters.A.state.excludedValues).toEqual({ id: 1, name: "three" });
325
320
  expect(listFilters.B.state.allowedValues).toEqual({ id: 2, name: "four" });
326
- expect(unrefAndToRawDeep(listFilters.A.parentState)).toEqual(unrefAndToRawDeep(listInstanceA.state));
327
- expect(unrefAndToRawDeep(listFilters.B.parentState)).toEqual(unrefAndToRawDeep(listInstanceB.state));
321
+ expect(unrefAndToRawDeep(listFilters.A.parentState)).toEqual(unrefAndToRawDeep(listFilterA.parentState));
322
+ expect(unrefAndToRawDeep(listFilters.B.parentState)).toEqual(unrefAndToRawDeep(listFilterB.parentState));
328
323
  expect(unrefAndToRawDeep(listFilters.A.state)).toEqual(unrefAndToRawDeep(listFilterA.state));
329
324
  expect(unrefAndToRawDeep(listFilters.B.state)).toEqual(unrefAndToRawDeep(listFilterB.state));
330
325
  });
@@ -1,4 +1,4 @@
1
- import { isEmpty } from "lodash";
1
+ import { cloneDeep, isEmpty } from "lodash";
2
2
  import { computed, effectScope, reactive, unref } from "vue";
3
3
  import { assignReactiveObject } from "../utils/assignReactiveObject";
4
4
  import inspect from "browser-util-inspect";
@@ -11,14 +11,14 @@ export class ListError extends Error {
11
11
  }
12
12
  }
13
13
 
14
- const defaultCrud = reactive({
14
+ const defaultCrud = {
15
15
  args: {},
16
16
  list: undefined,
17
- });
17
+ };
18
18
 
19
19
  export function setListInstanceCrud({ list, args = {} } = {}) {
20
20
  defaultCrud.list = list;
21
- assignReactiveObject(defaultCrud.args, args);
21
+ Object.assign(defaultCrud.args, args);
22
22
  }
23
23
 
24
24
  export function useListInstances(listInstanceArgs) {
@@ -43,7 +43,7 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
43
43
  error: null,
44
44
  order: [],
45
45
  });
46
- assignReactiveObject(state.listInstanceCrud, defaultCrud);
46
+ Object.assign(state.listInstanceCrud, cloneDeep(defaultCrud));
47
47
  if (crudArgs) {
48
48
  assignReactiveObject(state.listInstanceCrud.args, crudArgs);
49
49
  }
@@ -1,4 +1,4 @@
1
- import { computed, effectScope, onScopeDispose, reactive, toRef, toRefs, watch } from "vue";
1
+ import { computed, effectScope, onScopeDispose, reactive, toRef, toRefs, unref, watch } from "vue";
2
2
  import { get, isArray, isEmpty, isUndefined } from "lodash";
3
3
  import { keyDiff } from "../utils/keyDiff";
4
4
 
@@ -45,10 +45,12 @@ export function useListRelated({
45
45
  state.relatedObjectsObjects[addedKey] = {};
46
46
  combinedEffectScopes[addedKey] = effectScope();
47
47
  combinedEffectScopes[addedKey].run(() => {
48
- state.objects[addedKey] = computed(() => ({
49
- ...toRefs(state.relatedObjectsObjects[addedKey]),
50
- ...toRefs(parentState.objects[addedKey]),
51
- }));
48
+ state.objects[addedKey] = computed(() =>
49
+ reactive({
50
+ ...toRefs(state.relatedObjectsObjects[addedKey]),
51
+ ...toRefs(parentState.objects[addedKey]),
52
+ })
53
+ );
52
54
  });
53
55
  }
54
56
  }
@@ -84,7 +86,8 @@ export function useListRelated({
84
86
  }
85
87
  for (const addedRuleKey of addedRuleKeys) {
86
88
  relatedObjectsObject[ropn][addedRuleKey] = computed(() => {
87
- const ruleObjects = state.relatedObjectsRules?.[addedRuleKey]?.objects;
89
+ // deal with computed objects being passed.
90
+ const ruleObjects = unref(state.relatedObjectsRules?.[addedRuleKey]?.objects);
88
91
  const rulePkKey = state.relatedObjectsRules?.[addedRuleKey]?.pkKey || addedRuleKey;
89
92
  if (!ruleObjects || !rulePkKey) {
90
93
  return undefined;
@@ -11,9 +11,9 @@ export class ListSubscriptionError extends Error {
11
11
  }
12
12
  }
13
13
 
14
- const defaultCrud = reactive({
14
+ const defaultCrud = {
15
15
  subscribe: undefined,
16
- });
16
+ };
17
17
 
18
18
  export function setListSubscriptionCrud({ subscribe }) {
19
19
  defaultCrud.subscribe = subscribe;
@@ -36,7 +36,7 @@ export function useListSubscription({ listInstance, crudArgs, defaultListArgs, d
36
36
  listSubscriptionCrud: {},
37
37
  intendToSubscribe: false,
38
38
  });
39
- assignReactiveObject(state.listSubscriptionCrud, defaultCrud);
39
+ assignReactiveObject(state.listSubscriptionCrud, cloneDeep(defaultCrud));
40
40
 
41
41
  async function subscribe({ listArgs, retrieveArgs } = {}) {
42
42
  if (!listArgs) {