From 6b5bda2d9ec4e49b13cc10347bc8c104b928c358 Mon Sep 17 00:00:00 2001 From: Quentin SCHROTER Date: Wed, 25 Sep 2024 16:04:15 +0200 Subject: [PATCH 1/6] may improve getMany mechanism --- src/Bones.UI/core/composableFactory.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Bones.UI/core/composableFactory.ts b/src/Bones.UI/core/composableFactory.ts index e9419c7..fbc70fc 100644 --- a/src/Bones.UI/core/composableFactory.ts +++ b/src/Bones.UI/core/composableFactory.ts @@ -1,4 +1,4 @@ -import { Ref, onUnmounted, ref } from "vue"; +import { Ref, onUnmounted, ref, computed } from "vue"; import { FilterFactory } from "./filterFactory"; import { INotifyService } from "../abstractions"; @@ -105,12 +105,15 @@ export class ComposableFactory { }); const fetching = ref(false); - const entities = ref([]) as Ref; + const _entities = ref([]) as Ref; + let _filter: (el: TInfos) => boolean = () => true; - const getMany = async (...args: [...TArgs, ((el: TDetails) => boolean)?]) => { + const entities = computed(() => _entities.value.filter(e => _filter(e))); + + const getMany = async (...args: [...TArgs, ((el: TInfos) => boolean)?]) => { fetching.value = true; - let customFilter: ((el: TDetails) => boolean) | undefined = undefined + let customFilter: ((el: TInfos) => boolean) | undefined = undefined if (args.length > 1 && typeof args[args.length - 1] === 'function') { customFilter = args.pop(); @@ -119,21 +122,22 @@ export class ComposableFactory { let actualArgs = args as unknown as TArgs; try { - entities.value = await method(...actualArgs); - if (apply) apply(entities) + _entities.value = await method(...actualArgs); + if (apply) apply(_entities) } finally { fetching.value = false; } const filterMethod = customFilter || (actualArgs.length > 0 ? FilterFactory.create(actualArgs[0]) : () => true); + _filter = filterMethod - subscribersIds.push(service.subscribe("all", onCollectionChanged(entities, filterMethod))); + subscribersIds.push(service.subscribe("all", onCollectionChanged(_entities))); subscribersIds.push(service.subscribe("reset", async () => { fetching.value = true; try { - entities.value = await method(...actualArgs); - if (apply) apply(entities) + _entities.value = await method(...actualArgs); + if (apply) apply(_entities) } finally { fetching.value = false; From f73b083a0e1afb15f2f7df86f31b36ee0f1ce06d Mon Sep 17 00:00:00 2001 From: Quentin SCHROTER Date: Wed, 25 Sep 2024 16:16:51 +0200 Subject: [PATCH 2/6] fix tests to match new getMany working way --- src/Bones.UI/core/composableFactory.ts | 8 +++++--- tests/Bones.UI.Tests/tests/composable.test.ts | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Bones.UI/core/composableFactory.ts b/src/Bones.UI/core/composableFactory.ts index fbc70fc..1d79449 100644 --- a/src/Bones.UI/core/composableFactory.ts +++ b/src/Bones.UI/core/composableFactory.ts @@ -106,9 +106,11 @@ export class ComposableFactory { const fetching = ref(false); const _entities = ref([]) as Ref; - let _filter: (el: TInfos) => boolean = () => true; + let _filter: Ref<(el: TInfos) => boolean> = ref(() => true); - const entities = computed(() => _entities.value.filter(e => _filter(e))); + const entities = computed(() => { + return _entities.value.filter(e => _filter.value(e)) + }); const getMany = async (...args: [...TArgs, ((el: TInfos) => boolean)?]) => { fetching.value = true; @@ -130,7 +132,7 @@ export class ComposableFactory { } const filterMethod = customFilter || (actualArgs.length > 0 ? FilterFactory.create(actualArgs[0]) : () => true); - _filter = filterMethod + _filter.value = filterMethod subscribersIds.push(service.subscribe("all", onCollectionChanged(_entities))); subscribersIds.push(service.subscribe("reset", async () => { diff --git a/tests/Bones.UI.Tests/tests/composable.test.ts b/tests/Bones.UI.Tests/tests/composable.test.ts index ad9a0a2..5883509 100644 --- a/tests/Bones.UI.Tests/tests/composable.test.ts +++ b/tests/Bones.UI.Tests/tests/composable.test.ts @@ -89,14 +89,14 @@ test('testComposableComplexeFilter', async () => { mock.onGet(buildURL(TEST_USERS_URL, {label: "test3"})).reply(200, [{ id: "1", label: "test1" },{ id: "2", label: "test2" }]); const { getMany, entities: users } = useTestUsers(); await getMany({ label: "test3"}); - expect(users.value?.length).toBe(2); + expect(users.value?.length).toBe(0); const { create, created } = useCreateTestUser(); mock.onPost(TEST_USERS_URL).reply(200, { id: "3", label: "filtered" }); await create({ label: "filtered" }); expect(created).toBeTruthy(); - expect(users.value?.length).toBe(2); + expect(users.value?.length).toBe(0); mock.onPost(TEST_USERS_URL).reply(200, { id: "4", label: "test3" }); await create({ label: "test3" }); expect(created).toBeTruthy(); - expect(users.value?.length).toBe(3); + expect(users.value?.length).toBe(1); }); \ No newline at end of file From 946dad3e4b070ecd4444fb156f947bbe5815b56c Mon Sep 17 00:00:00 2001 From: rduteil Date: Mon, 10 Feb 2025 17:15:06 +0100 Subject: [PATCH 3/6] Add CancellationToken mechanism --- src/Bones.UI/core/composableFactory.ts | 211 ++++++++++++++++++------- src/Bones.UI/core/serviceFactory.ts | 66 ++++---- 2 files changed, 184 insertions(+), 93 deletions(-) diff --git a/src/Bones.UI/core/composableFactory.ts b/src/Bones.UI/core/composableFactory.ts index b2d9aa8..6620213 100644 --- a/src/Bones.UI/core/composableFactory.ts +++ b/src/Bones.UI/core/composableFactory.ts @@ -5,24 +5,43 @@ import { INotifyService } from "../abstractions"; import { onCollectionChanged, onEntityChanged } from "../tools"; export class ComposableFactory { - public static get(service: { get(id: string): Promise } & INotifyService, applyFactory?: () => (entity: Ref) => void) { - return ComposableFactory.customGet(service, service.get, applyFactory); + public static get( + service: { get(id: string, cancellationToken?: AbortController): Promise } & INotifyService, + applyFactory?: () => (entity: Ref) => void, + allowCancellation: boolean = true + ) { + return ComposableFactory.customGet(service, service.get, applyFactory, allowCancellation); } - public static getMany(service: { getMany(filter?: TFilter): Promise } & INotifyService, applyFactory?: () => (entities: Ref) => void) { - return ComposableFactory.customGetMany(service, service.getMany, applyFactory); + public static getMany( + service: { getMany(filter?: TFilter, cancellationToken?: AbortController): Promise } & INotifyService, + applyFactory?: () => (entities: Ref) => void, + allowCancellation: boolean = true + ) { + return ComposableFactory.customGetMany(service, service.getMany, applyFactory, allowCancellation); } - public static create(service: { create(payload: TCreateDTO): Promise } & INotifyService, applyFactory?: () => (entity: Ref) => void) { - return ComposableFactory.customCreate(service, service.create, applyFactory); + public static create( + service: { create(payload: TCreateDTO, cancellationToken?: AbortController): Promise } & INotifyService, + applyFactory?: () => (entity: Ref) => void, + allowCancellation: boolean = true + ) { + return ComposableFactory.customCreate(service, service.create, applyFactory, allowCancellation); } - public static update(service: { update(id: string, payload: TUpdateDTO): Promise } & INotifyService, applyFactory?: () => (entity: Ref) => void) { - return ComposableFactory.customUpdate(service, service.update, applyFactory); + public static update( + service: { update(id: string, payload: TUpdateDTO, cancellationToken?: AbortController): Promise } & INotifyService, + applyFactory?: () => (entity: Ref) => void, + allowCancellation: boolean = true + ) { + return ComposableFactory.customUpdate(service, service.update, applyFactory, allowCancellation); } - public static remove(service: { remove(id: string): Promise }) { - return ComposableFactory.customRemove(service.remove); + public static remove( + service: { remove(id: string, cancellationToken?: AbortController): Promise }, + allowCancellation: boolean = true + ) { + return ComposableFactory.customRemove(service.remove, allowCancellation); } public static subscribe(service: INotifyService) { @@ -46,7 +65,10 @@ export class ComposableFactory { } } - public static custom(method: (...args: TArgs) => Promise, applyFactory?: () => (entity: Ref) => void) { + public static custom( + method: (...args: TArgs) => Promise, + applyFactory?: () => (entity: Ref) => void + ) { return () => { const apply = applyFactory ? applyFactory() : () => { }; @@ -74,48 +96,16 @@ export class ComposableFactory { } } - - public static customGet(service: INotifyService, method: (...args: TArgs) => Promise, applyFactory?: () => (entity: Ref) => void) { - return () => { - const apply = applyFactory ? applyFactory() : () => { }; - let subscribersIds: number[] = []; - - onUnmounted(() => { - subscribersIds.forEach(id => service.unsubscribe(id)); - subscribersIds = []; - }); - - const getting = ref(false); - const entity = ref(null) as Ref; - - const get = async (...args: TArgs) => { - getting.value = true; - try { - entity.value = await method(...args); - if (apply) apply(entity as Ref); - } - finally { - getting.value = false; - } - - subscribersIds.push(service.subscribe("all", onEntityChanged(entity, apply))); - - return entity; - } - - return { - getting: getting, - get, - entity: entity - } - } - } - /** * Warning : read the code before using this method, the first argument in the method is used to create a filter * The last argument passed to the getMany composable can be a custom filter function that will override the default filter * */ - public static customGetMany(service: INotifyService, method: (...args: TArgs) => Promise, applyFactory?: () => (entities: Ref) => void) { + public static customGetMany( + service: INotifyService, + method: (...args: [...TArgs, AbortController]) => Promise, + applyFactory?: () => (entities: Ref) => void, + allowCancellation: boolean = true + ) { return () => { const apply = applyFactory ? applyFactory() : () => { }; let subscribersIds: number[] = []; @@ -128,7 +118,13 @@ export class ComposableFactory { const fetching = ref(false); const entities = ref([]) as Ref; + let cancellationToken: AbortController | null = null; + const getMany = async (...args: [...TArgs, ((el: TDetails) => boolean)?]) => { + if (cancellationToken && allowCancellation) { + cancellationToken.abort(); + cancellationToken = null; + } fetching.value = true; let customFilter: ((el: TDetails) => boolean) | undefined = undefined @@ -140,7 +136,8 @@ export class ComposableFactory { let actualArgs = args as unknown as TArgs; try { - entities.value = await method(...actualArgs); + cancellationToken = new AbortController(); + entities.value = await method(...actualArgs, cancellationToken); if (apply) apply(entities) } finally { @@ -151,9 +148,14 @@ export class ComposableFactory { subscribersIds.push(service.subscribe("all", onCollectionChanged(entities, filterMethod))); subscribersIds.push(service.subscribe("reset", async () => { + if (cancellationToken && allowCancellation) { + cancellationToken.abort(); + cancellationToken = null; + } fetching.value = true; try { - entities.value = await method(...actualArgs); + cancellationToken = new AbortController(); + entities.value = await method(...actualArgs, cancellationToken); if (apply) apply(entities) } finally { @@ -167,12 +169,67 @@ export class ComposableFactory { return { fetching: fetching, getMany, - entities: entities + entities: entities, + cancellationToken + } + } + } + + public static customGet( + service: INotifyService, + method: (...args: [...TArgs, AbortController]) => Promise, + applyFactory?: () => (entity: Ref) => void, + allowCancellation: boolean = true + ) { + return () => { + const apply = applyFactory ? applyFactory() : () => { }; + let subscribersIds: number[] = []; + + onUnmounted(() => { + subscribersIds.forEach(id => service.unsubscribe(id)); + subscribersIds = []; + }); + + const getting = ref(false); + const entity = ref(null) as Ref; + + let cancellationToken: AbortController | null = null; + + const get = async (...args: TArgs) => { + if (cancellationToken && allowCancellation) { + cancellationToken.abort(); + cancellationToken = null; + } + getting.value = true; + try { + cancellationToken = new AbortController(); + entity.value = await method(...args, cancellationToken); + if (apply) apply(entity as Ref); + } + finally { + getting.value = false; + } + + subscribersIds.push(service.subscribe("all", onEntityChanged(entity, apply))); + + return entity; + } + + return { + getting: getting, + get, + entity: entity, + cancellationToken } } } - public static customCreate(service: INotifyService, method: (...args: TArgs) => Promise, applyFactory?: () => (entity: Ref) => void) { + public static customCreate( + service: INotifyService, + method: (...args: [...TArgs, AbortController]) => Promise, + applyFactory?: () => (entity: Ref) => void, + allowCancellation: boolean = true + ) { return () => { const apply = applyFactory ? applyFactory() : () => { }; let subscribersIds: number[] = []; @@ -185,10 +242,17 @@ export class ComposableFactory { const creating = ref(false); const created = ref(null) as Ref; + let cancellationToken: AbortController | null = null; + const create = async (...args: TArgs) => { + if (cancellationToken && allowCancellation) { + cancellationToken.abort(); + cancellationToken = null; + } creating.value = true; try { - created.value = await method(...args); + cancellationToken = new AbortController(); + created.value = await method(...args, cancellationToken); if (apply) apply(created as Ref); } finally { @@ -203,12 +267,18 @@ export class ComposableFactory { return { creating: creating, create, - created: created + created: created, + cancellationToken } } } - public static customUpdate(service: INotifyService, method: (...args: TArgs) => Promise, applyFactory?: () => (entity: Ref) => void) { + public static customUpdate( + service: INotifyService, + method: (...args: [...TArgs, AbortController]) => Promise, + applyFactory?: () => (entity: Ref) => void, + allowCancellation: boolean = true + ) { return () => { const apply = applyFactory ? applyFactory() : () => { }; let subscribersIds: number[] = []; @@ -221,10 +291,17 @@ export class ComposableFactory { const updating = ref(false); const updated = ref(null) as Ref; + let cancellationToken: AbortController | null = null; + const update = async (...args: TArgs) => { + if (cancellationToken && allowCancellation) { + cancellationToken.abort(); + cancellationToken = null; + } updating.value = true; try { - updated.value = await method(...args); + cancellationToken = new AbortController(); + updated.value = await method(...args, cancellationToken); if (apply) apply(updated as Ref); } finally { @@ -239,19 +316,30 @@ export class ComposableFactory { return { updating: updating, update, - updated: updated + updated: updated, + cancellationToken } } } - public static customRemove(method: (...args: TArgs) => Promise) { + public static customRemove( + method: (...args: [...TArgs, AbortController]) => Promise, + allowCancellation: boolean = true + ) { return () => { const removing = ref(false); + let cancellationToken: AbortController | null = null; + const remove = async (...args: TArgs) => { + if (cancellationToken && allowCancellation) { + cancellationToken.abort(); + cancellationToken = null; + } removing.value = true; try { - await method(...args); + cancellationToken = new AbortController(); + await method(...args, cancellationToken); } finally { removing.value = false; @@ -260,7 +348,8 @@ export class ComposableFactory { return { removing: removing, - remove + remove, + cancellationToken } } } diff --git a/src/Bones.UI/core/serviceFactory.ts b/src/Bones.UI/core/serviceFactory.ts index 6006535..ca1b258 100644 --- a/src/Bones.UI/core/serviceFactory.ts +++ b/src/Bones.UI/core/serviceFactory.ts @@ -1,4 +1,4 @@ -import axios, { AxiosInstance, AxiosResponse } from "axios"; +import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; import { buildURL } from "../tools"; import { NotifyService } from "./notifyService"; @@ -34,13 +34,30 @@ export class ServiceFactory { )); } + static addCustom( + name: T, + call: (axios: AxiosInstance, ...args: TArgs) => Promise, + mapper: (dto: TResultDTO) => TResult + ): Record Promise> { + + const fetch = async (...args: TArgs) => { + const response = await call(ServiceFactory.http, ...args); + const dto: TResultDTO = response.data; + + const result = mapper(dto); + + return result; + } + + return { [name]: fetch } as Record Promise>; + } + addGetMany(url: string | (() => string), entity: new (dto: TInfosDTO) => TInfos) - : { getMany: (filter?: TFilter) => Promise } { + : { getMany: (filter?: TFilter, cancellationToken?: AbortController) => Promise } { - const getMany = async (filter?: TFilter) => { + const getMany = async (filter?: TFilter, cancellationToken?: AbortController) => { const realUrl = typeof url === "string" ? url : url(); - - const response = await ServiceFactory.http.get(buildURL(realUrl, filter)); + const response = await ServiceFactory.http.get(buildURL(realUrl, filter), { signal: cancellationToken?.signal } as AxiosRequestConfig); const dtos: TInfosDTO[] = response.data; return dtos.map(dto => new entity(dto)); @@ -51,10 +68,10 @@ export class ServiceFactory { addGet(url: (id: string) => string) - : { get: (id: string) => Promise } { + : { get: (id: string, cancellationToken?: AbortController) => Promise } { - const get = async (id: string) => { - const response = await ServiceFactory.http.get(url(id)); + const get = async (id: string, cancellationToken?: AbortController) => { + const response = await ServiceFactory.http.get(url(id), { signal: cancellationToken?.signal } as AxiosRequestConfig); const dto: TDetailsDTO = response.data; const result = new this.EntityDetails(dto); @@ -65,26 +82,12 @@ export class ServiceFactory { return { get }; } - static addCustom(name: T, call: (axios: AxiosInstance, ...args: TArgs) => Promise, mapper: (dto: TResultDTO) => TResult): Record Promise> { - - const fetch = async (...args: TArgs) => { - const response = await call(ServiceFactory.http, ...args); - const dto: TResultDTO = response.data; - - const result = mapper(dto); - - return result; - } - - return { [name]: fetch } as Record Promise>; - } - addCreate(url: string | (() => string)) - : { create: (dto: TCreateDTO) => Promise } { + : { create: (dto: TCreateDTO, cancellationToken?: AbortController) => Promise } { - const create = async (dto: TCreateDTO) => { + const create = async (dto: TCreateDTO, cancellationToken?: AbortController) => { const realUrl = typeof url === "string" ? url : url(); - const response = await ServiceFactory.http.post(realUrl, dto); + const response = await ServiceFactory.http.post(realUrl, dto, { signal: cancellationToken?.signal } as AxiosRequestConfig); const result = new this.EntityDetails(response.data); if (this.notifyService) @@ -97,10 +100,10 @@ export class ServiceFactory { } addUpdate(url: (id: string) => string) - : { update: (id: string, dto: TUpdateDTO) => Promise } { + : { update: (id: string, dto: TUpdateDTO, cancellationToken?: AbortController) => Promise } { - const update = async (id: string, dto: TUpdateDTO) => { - const response = await ServiceFactory.http.post(url(id), dto); + const update = async (id: string, dto: TUpdateDTO, cancellationToken?: AbortController) => { + const response = await ServiceFactory.http.post(url(id), dto, { signal: cancellationToken?.signal } as AxiosRequestConfig); const result = new this.EntityDetails(response.data); if (this.notifyService) @@ -113,10 +116,10 @@ export class ServiceFactory { } addRemove(url: (id: string) => string) - : { remove: (id: string) => Promise } { + : { remove: (id: string, cancellationToken?: AbortController) => Promise } { - const remove = async (id: string) => { - await ServiceFactory.http.delete(url(id)); + const remove = async (id: string, cancellationToken?: AbortController) => { + await ServiceFactory.http.delete(url(id), { signal: cancellationToken?.signal } as AxiosRequestConfig); if (this.notifyService) this.notifyService.notify("delete", id); @@ -137,7 +140,6 @@ export class ServiceFactory { return { subscribe: subscribe.bind(notifyService), unsubscribe: unsubscribe.bind(notifyService), ...otherMethods }; } - build(target: T): T; build(target: T, source1: U): T & U; build(target: T, source1: U, source2: V): T & U & V; From ec7c36c30616ee1b4eec11d5a5f4ec849a37bc52 Mon Sep 17 00:00:00 2001 From: rduteil Date: Mon, 10 Feb 2025 17:29:59 +0100 Subject: [PATCH 4/6] Fix tests --- tests/Bones.UI.Tests/services/testUserService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Bones.UI.Tests/services/testUserService.ts b/tests/Bones.UI.Tests/services/testUserService.ts index 2bb3b96..970f05d 100644 --- a/tests/Bones.UI.Tests/services/testUserService.ts +++ b/tests/Bones.UI.Tests/services/testUserService.ts @@ -16,8 +16,8 @@ const AccountLoginFactory = new ServiceFactory axios.post(TEST_USERS_URL, d), (dto: TestUserDetailsDTO) => new Array(5).map(a => new TestUserDetails(dto))), ServiceFactory.addCustom("logout", axios => axios.get(TEST_USERS_URL), (dto: TestUserDetailsDTO) => new TestUserDetails(dto)), ServiceFactory.addCustom("current", axios => axios.get(TEST_USERS_URL), (dto: TestUserDetailsDTO) => new TestUserDetails(dto)), - ServiceFactory.addCustom("complexCurrent", (axios, p1: string, p2: number) => axios.get(TEST_USERS_URL), (dto: TestUserDetailsDTO) => new TestUserDetails(dto)), - ServiceFactory.addCustom("complexGetMany", (axios, p1: string, p2: number) => axios.get(TEST_USERS_URL), (dto: TestUserDetailsDTO) => new Array(5).map(a => new TestUserDetails(dto))), + ServiceFactory.addCustom("complexCurrent", (axios, p1: string, p2: number, _?: AbortController) => axios.get(TEST_USERS_URL), (dto: TestUserDetailsDTO) => new TestUserDetails(dto)), + ServiceFactory.addCustom("complexGetMany", (axios, p1: string, p2: number, _?: AbortController) => axios.get(TEST_USERS_URL), (dto: TestUserDetailsDTO) => new Array(5).map(a => new TestUserDetails(dto))), )); export const useTestUsersSync = ComposableFactory.sync(testUserServiceFactory); From 90e816a8f5aa357b839a5967d1a6aa57d13eb937 Mon Sep 17 00:00:00 2001 From: rduteil Date: Tue, 11 Feb 2025 09:24:30 +0100 Subject: [PATCH 5/6] cancellationToken to null in finally --- src/Bones.UI/core/composableFactory.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Bones.UI/core/composableFactory.ts b/src/Bones.UI/core/composableFactory.ts index 6620213..9497ad8 100644 --- a/src/Bones.UI/core/composableFactory.ts +++ b/src/Bones.UI/core/composableFactory.ts @@ -141,6 +141,7 @@ export class ComposableFactory { if (apply) apply(entities) } finally { + cancellationToken = null; fetching.value = false; } @@ -159,6 +160,7 @@ export class ComposableFactory { if (apply) apply(entities) } finally { + cancellationToken = null; fetching.value = false; } })); @@ -207,6 +209,7 @@ export class ComposableFactory { if (apply) apply(entity as Ref); } finally { + cancellationToken = null; getting.value = false; } @@ -256,6 +259,7 @@ export class ComposableFactory { if (apply) apply(created as Ref); } finally { + cancellationToken = null; creating.value = false; } @@ -305,6 +309,7 @@ export class ComposableFactory { if (apply) apply(updated as Ref); } finally { + cancellationToken = null; updating.value = false; } @@ -342,6 +347,7 @@ export class ComposableFactory { await method(...args, cancellationToken); } finally { + cancellationToken = null; removing.value = false; } } From ea445bf48f8a0b24e54a4c468cd358ab244d973b Mon Sep 17 00:00:00 2001 From: rduteil Date: Tue, 11 Feb 2025 09:27:09 +0100 Subject: [PATCH 6/6] =?UTF-8?q?Pour=20faire=20plaisir=20=C3=A0=20Thomas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Bones.UI/core/composableFactory.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Bones.UI/core/composableFactory.ts b/src/Bones.UI/core/composableFactory.ts index 9497ad8..308cb5b 100644 --- a/src/Bones.UI/core/composableFactory.ts +++ b/src/Bones.UI/core/composableFactory.ts @@ -126,6 +126,7 @@ export class ComposableFactory { cancellationToken = null; } fetching.value = true; + cancellationToken = new AbortController(); let customFilter: ((el: TDetails) => boolean) | undefined = undefined @@ -136,7 +137,6 @@ export class ComposableFactory { let actualArgs = args as unknown as TArgs; try { - cancellationToken = new AbortController(); entities.value = await method(...actualArgs, cancellationToken); if (apply) apply(entities) } @@ -154,8 +154,8 @@ export class ComposableFactory { cancellationToken = null; } fetching.value = true; + cancellationToken = new AbortController(); try { - cancellationToken = new AbortController(); entities.value = await method(...actualArgs, cancellationToken); if (apply) apply(entities) } @@ -203,8 +203,8 @@ export class ComposableFactory { cancellationToken = null; } getting.value = true; + cancellationToken = new AbortController(); try { - cancellationToken = new AbortController(); entity.value = await method(...args, cancellationToken); if (apply) apply(entity as Ref); } @@ -253,8 +253,8 @@ export class ComposableFactory { cancellationToken = null; } creating.value = true; + cancellationToken = new AbortController(); try { - cancellationToken = new AbortController(); created.value = await method(...args, cancellationToken); if (apply) apply(created as Ref); } @@ -303,8 +303,8 @@ export class ComposableFactory { cancellationToken = null; } updating.value = true; + cancellationToken = new AbortController(); try { - cancellationToken = new AbortController(); updated.value = await method(...args, cancellationToken); if (apply) apply(updated as Ref); } @@ -342,8 +342,8 @@ export class ComposableFactory { cancellationToken = null; } removing.value = true; + cancellationToken = new AbortController(); try { - cancellationToken = new AbortController(); await method(...args, cancellationToken); } finally {