-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
When a resource is in a failing state for any reason and you try to patchState
, the console will display an error and the action will be skipped.

This behavior can be reproduced with this store and calling any increment method.
If I'm doing something wrong, please let me know.
import { withResource } from '@angular-architects/ngrx-toolkit';
import { resource } from '@angular/core';
import { patchState, signalStore, withMethods, withState } from '@ngrx/signals';
export const Store = signalStore(
{
providedIn: 'root',
},
withState({
count: 0,
}),
withResource(() => ({
test: resource({
loader: () => {
console.log('test');
// throw new Error('test');
return Promise.reject('test');
},
}),
// test2: httpResource(() => 'https://www.not-exist'),
})),
withMethods((store) => ({
increment() {
patchState(store, { count: store.count() + 1 });
},
increment2() {
patchState(store, (state) => ({ ...state, count: state.count + 1 }));
},
}))
);
Checking the ngrx/platform
patchState
code, the issue is because when we call patchState
, this call internally calls getState that gets the value.

Metadata
Metadata
Assignees
Labels
No labels