readonly addItem$ = new Subject<CreateItemDto | null>();
readonly #addItem = toSignal(this.addItem$);
readonly addItemResource = rxResource({
request: this.#addItem,
loader: ({ request }) =>
from(
this.#http.post<OperationResultsOfCreatedItemDto>(
this.#itemApi.client.items.toPostRequestInformation({}).URL,
request
)
).pipe(map((q) => q?.data ?? {})),
});
When I do
this.addItem$.next(payload)
the request works fine and the resource status becomes Resolved as expected.
However, I'd like to automatically reset the resource status to Idle after the request completes successfully – without having to manually emit null again like this:
constructor() {
explicitEffect(
[this.itemsService.addItemResource.status],
([addItemStatus]) => {
if (addItemStatus === ResourceStatus.Resolved) {
this.itemsService.addItem$.next(null);
}
}
);
}
Is there a recommended pattern to automatically reset the resource status inside the loader? Maybe using finalize or something better with signals?