@arrai-innovations/reactive-helpers 11.2.0 → 11.3.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/docs.md CHANGED
@@ -686,12 +686,13 @@ The configuration options used to create a list subscription.
686
686
  **Kind**: global typedef
687
687
  **Properties**
688
688
 
689
- | Name | Type | Description |
690
- | ------------ | ---------------- | ---------------------------------------------------------------------------------------- |
691
- | props | `object` | passed on to a created list instance if one is not provided |
692
- | functions | `object` | passed on to a created list instance if one is not provided |
693
- | listInstance | [`ListInstance`] | a list instance to use instead of creating one |
694
- | keepOldPages | `boolean` | if true, pages will not be cleared when defaultPageCallback is called. default is false. |
689
+ | Name | Type | Description |
690
+ | ------------------------------ | ---------------- | ---------------------------------------------------------------------------------------- |
691
+ | props | `object` | passed on to a created list instance if one is not provided |
692
+ | functions | `object` | passed on to a created list instance if one is not provided |
693
+ | listInstance | [`ListInstance`] | a list instance to use instead of creating one |
694
+ | keepOldPages | `boolean` | if true, pages will not be cleared when defaultPageCallback is called. default is false. |
695
+ | clearListOnListIntentTriggered | `boolean` | if true, the list will be cleared when the list intent is triggered. default is false. |
695
696
 
696
697
  ## ListSubscriptionState
697
698
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "11.2.0",
3
+ "version": "11.3.0",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -615,4 +615,52 @@ describe("use/listSubscription.spec.js", function () {
615
615
  expect(inspect(listSubscription.A)).toEqual(inspect(listSubscriptionA));
616
616
  expect(inspect(listSubscription.B)).toEqual(inspect(listSubscriptionB));
617
617
  });
618
+ describe("clearListOnListIntentTriggered true", function () {
619
+ it("on true", async function () {
620
+ crudSubscribeResolvable[0].promise.cancel.mockImplementation(() => Promise.resolve(true));
621
+ const listArgs = reactive({
622
+ user: 1,
623
+ });
624
+ const retrieveArgs = reactive({
625
+ fields: fields,
626
+ });
627
+ const listInstance = useListInstance({
628
+ props: { listArgs, retrieveArgs },
629
+ });
630
+ listInstance.clearList = vi.fn().mockImplementationOnce(() => undefined);
631
+ const listSubscription = useListSubscription({
632
+ listInstance,
633
+ clearListOnListIntentTriggered: true,
634
+ });
635
+ listSubscription.subscribe();
636
+ await nextTick();
637
+ await flushPromises();
638
+ listArgs.user = 2;
639
+ expect(listInstance.clearList).toHaveBeenCalledTimes(1);
640
+ });
641
+ });
642
+ describe("clearListOnListIntentTriggered false", function () {
643
+ it("on true", async function () {
644
+ crudSubscribeResolvable[0].promise.cancel.mockImplementation(() => Promise.resolve(true));
645
+ const listArgs = reactive({
646
+ user: 1,
647
+ });
648
+ const retrieveArgs = reactive({
649
+ fields: fields,
650
+ });
651
+ const listInstance = useListInstance({
652
+ props: { listArgs, retrieveArgs },
653
+ });
654
+ listInstance.clearList = vi.fn().mockImplementationOnce(() => undefined);
655
+ const listSubscription = useListSubscription({
656
+ listInstance,
657
+ clearListOnListIntentTriggered: false,
658
+ });
659
+ listSubscription.subscribe();
660
+ await nextTick();
661
+ await flushPromises();
662
+ listArgs.user = 2;
663
+ expect(listInstance.clearList).toHaveBeenCalledTimes(0);
664
+ });
665
+ });
618
666
  });
package/use/list.js CHANGED
@@ -31,6 +31,7 @@ export const useList = ({
31
31
  functions = {},
32
32
  paged = false,
33
33
  keepOldPages = false,
34
+ clearListOnListIntentTriggered = false,
34
35
  searchThrottle = 500,
35
36
  sortThrottleWait,
36
37
  searchShowAllWhenEmpty,
@@ -63,6 +64,7 @@ export const useList = ({
63
64
 
64
65
  managed.listSubscription = useListSubscription({
65
66
  listInstance: managed.listInstance,
67
+ clearListOnListIntentTriggered,
66
68
  });
67
69
  managed.listSubscription.state.intendToList = toRef(props, "intendToList");
68
70
  managed.listSubscription.state.intendToSubscribe = toRef(props, "intendToSubscribe");
@@ -22,6 +22,7 @@ export class ListSubscriptionError extends Error {
22
22
  * @property {object} functions - passed on to a created list instance if one is not provided
23
23
  * @property {ListInstance} listInstance - a list instance to use instead of creating one
24
24
  * @property {boolean} keepOldPages - if true, pages will not be cleared when defaultPageCallback is called. default is false.
25
+ * @property {boolean} clearListOnListIntentTriggered - if true, the list will be cleared when the list intent is triggered. default is false.
25
26
  */
26
27
 
27
28
  /* eslint-disable jsdoc/check-types */
@@ -70,7 +71,13 @@ export function useListSubscriptions(args, listInstances = {}) {
70
71
  * @param {ListSubscriptionOptions} options - the configuration options for the list subscription
71
72
  * @returns {ListSubscription} - the list subscription
72
73
  */
73
- export function useListSubscription({ listInstance, props, functions, keepOldPages = false }) {
74
+ export function useListSubscription({
75
+ listInstance,
76
+ props,
77
+ functions,
78
+ keepOldPages = false,
79
+ clearListOnListIntentTriggered = false,
80
+ }) {
74
81
  if (!listInstance && !props) {
75
82
  throw new ListSubscriptionError("useListSubscription should be passed listInstance or props and functions.");
76
83
  }
@@ -233,7 +240,12 @@ export function useListSubscription({ listInstance, props, functions, keepOldPag
233
240
  state.subscribed = toRef(subscribeIntent.state, "active");
234
241
 
235
242
  listIntent = useCancellableIntent({
236
- awaitableWithCancel: listInstance.list,
243
+ awaitableWithCancel: () => {
244
+ if (clearListOnListIntentTriggered) {
245
+ listInstance.clearList();
246
+ }
247
+ return listInstance.list();
248
+ },
237
249
  watchArguments: reactive({
238
250
  intendToList: toRef(state, "intendToList"),
239
251
  listArgs: toRef(parentState, "listArgs"),