@arrai-innovations/reactive-helpers 11.0.3 → 11.0.5

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": "11.0.3",
3
+ "version": "11.0.5",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -3,7 +3,7 @@ import { nextTick, reactive, ref, unref } from "vue";
3
3
  import { deepUnref } from "vue-deepunref";
4
4
 
5
5
  describe("use/listSearch", () => {
6
- let useListInstance, useListSearch, useListSearches, useListSort, useListRelated, useListCalculated;
6
+ let useListInstance, useListSearch, useListSearches, useListSort, useListRelated, useListCalculated, useListFilter;
7
7
  beforeEach(async () => {
8
8
  const listInstanceModule = await import("../../../use/listInstance");
9
9
  useListInstance = listInstanceModule.useListInstance;
@@ -16,6 +16,8 @@ describe("use/listSearch", () => {
16
16
  useListRelated = listRelatedModule.useListRelated;
17
17
  const listCalculatedModule = await import("../../../use/listCalculated");
18
18
  useListCalculated = listCalculatedModule.useListCalculated;
19
+ const listFilterModule = await import("../../../use/listFilter");
20
+ useListFilter = listFilterModule.useListFilter;
19
21
  });
20
22
  it("should match by search term", async () => {
21
23
  const textSearchValue = ref("one");
@@ -502,4 +504,76 @@ describe("use/listSearch", () => {
502
504
  prop: "running",
503
505
  });
504
506
  });
507
+ it("should update when parentState is filtered in pass through mode.", async () => {
508
+ const listInstance = useListInstance({
509
+ props: {},
510
+ });
511
+ const allowedFilter = ref((obj) => !obj.filtered);
512
+ const listFilter = useListFilter({
513
+ parentState: listInstance.state,
514
+ allowedFilter,
515
+ });
516
+ const textSearchValue = ref("");
517
+ const listSearch = useListSearch({
518
+ parentState: listFilter.state,
519
+ props: reactive({
520
+ textSearchRules: ["name"],
521
+ textSearchValue,
522
+ }),
523
+ throttle: 20,
524
+ });
525
+ await doAwaitNot({
526
+ obj: listSearch.state,
527
+ prop: "running",
528
+ });
529
+ expect(listSearch.state.objects).toEqual({});
530
+ expect(listSearch.state.order).toEqual([]);
531
+ expect(listSearch.state.objectsInOrder).toEqual([]);
532
+ listInstance.addListObject({
533
+ id: 1,
534
+ filtered: false,
535
+ });
536
+ listInstance.addListObject({
537
+ id: 2,
538
+ filtered: true,
539
+ });
540
+ listInstance.addListObject({
541
+ id: 3,
542
+ filtered: false,
543
+ });
544
+ await doAwaitNot({
545
+ obj: listSearch.state,
546
+ prop: "running",
547
+ });
548
+ expect(listSearch.state.objects).toEqual({
549
+ 1: {
550
+ id: 1,
551
+ filtered: false,
552
+ },
553
+ 3: {
554
+ id: 3,
555
+ filtered: false,
556
+ },
557
+ });
558
+ expect(listSearch.state.order).toEqual(["1", "3"]);
559
+ expect(listSearch.state.objectsInOrder.map((e) => e.id)).toEqual([1, 3]);
560
+ listInstance.state.objects[2].filtered = false;
561
+ listInstance.state.objects[1].filtered = true;
562
+ await doAwaitNot({
563
+ obj: listSearch.state,
564
+ prop: "running",
565
+ });
566
+ expect(listSearch.state.objects).toEqual({
567
+ 2: {
568
+ id: 2,
569
+ filtered: false,
570
+ },
571
+ 3: {
572
+ id: 3,
573
+ filtered: false,
574
+ },
575
+ });
576
+ expect(listSearch.state.order).toEqual(["2", "3"]);
577
+ expect(listSearch.state.objectsInOrder.map((e) => e.id)).toEqual([2, 3]);
578
+ });
505
579
  });
package/use/listSearch.js CHANGED
@@ -274,7 +274,7 @@ export function useListSearch({ parentState, props, throttle = 500, showAllWhenE
274
274
  state.order = parentState.order.filter((id) => !!state.objects[id]);
275
275
  assignReactiveObject(
276
276
  state.objectsInOrderRefs,
277
- parentState.order.filter((id) => !!state.objects[id]).map((id) => toRef(state.objects, id))
277
+ state.order.map((id) => toRef(state.objects, id))
278
278
  );
279
279
  };
280
280
 
@@ -336,7 +336,7 @@ export function useListSearch({ parentState, props, throttle = 500, showAllWhenE
336
336
  }
337
337
  );
338
338
 
339
- watch(toRef(parentState, "order"), updateOrder, {
339
+ watch([() => Object.keys(state.objects), toRef(parentState, "order")], updateOrder, {
340
340
  immediate: true,
341
341
  deep: true,
342
342
  });
@@ -309,7 +309,7 @@ function recursiveInner(target, source, exclude, addedKeys, sameKeys, path, fn)
309
309
  const keysForRecurse = [];
310
310
  const keysForReplace = [];
311
311
  for (const key of sameKeys) {
312
- if (!exclude.includes(key)) {
312
+ if (!exclude?.includes(key)) {
313
313
  if (isObject(source[key]) && isObject(target[key])) {
314
314
  keysForRecurse.push(key);
315
315
  } else if (target[key] !== source[key]) {