-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Which @ngrx/* package(s) are relevant/related to the feature request?
store
Information
One of the most requested features that was missing in the Component Store was its integration into DevTools. The SignalStore, unlike the global store, doesn't have a single state either.
To address this, I propose introducing an option called withDevTools(name: string). This option would define the "feature key" of the Store and determine how it appears in the DevTools.
If the name is used multiple times, it should be automatically indexed. For example, withDevTools('user') would result in entries like user(1), user(2), and so on.
Furthermore, I suggest adding an optional parameter to the $update function that allows developers to set the name of the action. If this parameter is omitted, the SignalStore should use the function's name as the action name. For instance, in the example below, the action name would be “addUser”.
Example:
import { signalStore, withMethods, withState } from '@ngrx/signals';
import {
EmptyFeatureResult,
SignalStoreFeature,
} from '../lib/signal-store-models';
declare function withDevTools(params: {
name: string;
}): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult>;
type User = { id: number; name: string };
type UsersState = { users: User[]; loading: boolean };
const UsersStore = signalStore(
withDevTools({ name: 'users' }),
withState<UsersState>({ users: [], loading: false }),
withMethods(({ $update, users }) => {
return {
addUser(user: User): void {
// $update method with optional action name
$update((state) => ({ ...state }), 'addUser');
},
};
})
);If accepted, I would be happy to provide an initial PR.
Describe any alternatives/workarounds you're currently using
No response
I would be willing to submit a PR to fix this issue
- Yes
- No