ngrx-signal-store
Skill0 starsChanged 2 months agoMITView on GitHub
Build, review, and test NgRx SignalStore state management in Angular, using production patterns pinned to the official @ngrx/signals docs. Use for any Angular state-management task, and on any mention of signalStore, signalState, withState, withComputed, withMethods, withHooks, withProps, patchState, protectedState, withEntities, entityConfig, deepComputed, rxMethod, signalMethod, or rxjs-interop. Prefer this over recalling NgRx from memory: the Signals API changed substantially and pre-v17 habits produce wrong code.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Ency1988/skillstheir own version, first seen Oct 11, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Ency1988/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository21 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- angular-developerSkill
- channels-setupSkill
- copilotkit-channelsSkill
- copilotkit-cliSkill
- copilotkitSkill
- csharp-asyncSkill
- csharp-docsSkill
- csharp-xunitSkill
- ef-coreSkill
- github-actions-efficiencySkill
- github-actions-hardeningSkill
- github-actions-runtime-upgrade-conventionsSkill
- inspector-docsSkill
- inspector-workbenchSkill
- intelligence-docsSkill
- microsoft-agent-frameworkSkill
- microsoft-docsSkill
- prdSkill
- setup-slack-channelSkill
- technical-writingSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 34
signalMethod: when you need to react to a signal but need no operators. - Very specific: line 37
Extract a
signalStoreFeature?: When the third store repeats the same shape. - Distinctive: line 98
Read these on demand — they are not loaded until you need them.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
NgRx Signal Store
Production guidance for @ngrx/signals. Pinned to 21.1.1 (sources.json); refresh with /ngrx-signals-sync.
This is not classic NgRx. There are no actions, reducers, effects, or dispatch unless you deliberately opt into the Events plugin. If you catch yourself reaching for createAction or createReducer, you are in the wrong library.
Mental model
A store is a composition of features, evaluated left to right. Each feature sees everything the features before it added, and contributes state, computed signals, props, or methods to what follows. signalStore(...) returns an injectable service.
State is a deeply-signalized tree: every object-literal member becomes a DeepSignal you can drill into (store.filter.query()), while primitives stay plain signals. State is protected by default — only the store's own methods may write to it, via patchState.
Production defaults
- Leave
protectedStateon. It is the default, and it is what stops components from reaching in and mutating state.signalStore({ protectedState: false }, …)exists, but it trades away the one guarantee that keeps data flow one-directional. Tests do not need it — useunprotected()from@ngrx/signals/testinginstead. - Choose the lifetime deliberately.
signalStore({ providedIn: 'root' }, …)gives one app-wide instance. Listing the store in a component's or route'sproviders: []ties its lifetime to that component, which is what you want for local, disposable state. - Inject via default parameters —
withMethods((store, books = inject(BooksService)) => ({ … })). It keeps the feature a plain function and stays testable. - Write state updaters as standalone functions returning
PartialStateUpdater<T>, not as store methods. They tree-shake, they test in isolation, and they compose in a single call:patchState(store, setAllEntities(books), setFulfilled()). - Prefix private members with
_._totals,_load()— inaccessible from outside the store, so the public surface stays intentional. - One store per entity type. Multiple collections in one store are supported, but the docs recommend dedicated stores, and it keeps each store's methods coherent.
- Never mutate in an updater.
patchStateupdaters must return new objects; mutating in place silently breaks change propagation.
Decision rules
signalState or signalStore? signalState is a signalized state container and nothing more — reach for it for local component state with no behavior attached. The moment you need methods, dependency injection, lifecycle hooks, or a lifetime you control, use signalStore.
rxMethod, signalMethod, or a plain method? This is the choice that most often gets made wrong.
rxMethodwhen the work can overlap or arrive out of order. Only RxJS gives youswitchMap(cancel the in-flight request — the fix for a search-as-you-type race),exhaustMap(ignore clicks while a submit is in flight), anddebounceTime. Any HTTP load driven by user input belongs here.signalMethodwhen you need to react to a signal but need no operators. It isrxMethodwithout RxJS and is markedly smaller —rxjsis only an optional peer of@ngrx/signals. It cannot cancel or sequence, so it is the wrong tool for racing requests.- A plain method in
withMethodsfor a one-shot imperative call. Not everything needs to be reactive.
Extract a signalStoreFeature? When the third store repeats the same shape. Loading/error status is the canonical case — withRequestStatus() with standalone setPending() / setFulfilled() / setError() updaters. Two stores sharing a shape is a coincidence; three is a feature.
withEntities or a plain array? Any keyed collection you update or remove by id. It gives you entityMap, ids, and a computed entities, and the updaters handle the bookkeeping. A short, read-only list is fine as a plain array in state.
The Events plugin? Only when one thing that happens must be observed by several stores, or you specifically want dispatch/reducer separation. If a single store owns the state and a method would do, write the method — the docs are explicit that the default approach suffices for most cases.
Shape of a production store
export const BooksStore = signalStore(
{ providedIn: 'root' }, // omit to scope it to a component's providers
withState<BooksState>({ query: '', order: 'asc' }),
withEntities<Book>(), // ids + entityMap + computed entities
withRequestStatus(), // reusable feature: pending / fulfilled / error
withComputed(({ entities, order }) => ({
sortedBooks: () => { // plain fn — withComputed wraps it in computed()
const dir = order() === 'asc' ? 1 : -1;
return entities().toSorted((a, b) => dir * a.title.localeCompare(b.title));
},
})),
withMethods((store, books = inject(BooksService)) => ({
loadByQuery: rxMethod<string>(
pipe(
debounceTime(300),
distinctUntilChanged(),
tap(() => patchState(store, setPending())),
switchMap((query) => // switchMap: a newer query cancels the older one
books.search(query).pipe(
tapResponse({ // keeps the rxMethod alive if the request errors
next: (found) => patchState(store, setAllEntities(found), setFulfilled()),
error: (e: Error) => patchState(store, setError(e.message)),
}),
),
),
),
),
})),
withHooks({
onInit(store) {
store.loadByQuery(store.query); // pass the signal itself: reloads whenever it changes
},
}),
);Passing store.query (the signal, not store.query()) into an rxMethod is the idiom that makes the load declarative — it re-runs on every change, with no manual subscription.
Full runnable versions of this and other shapes are in references/recipes.md.
Traps
withDevtoolsis not part of NgRx. It comes from the third-party@angular-architects/ngrx-toolkit. It is a common hallucination — do not present it as official, and add the dependency if a project actually wants it.- Calling
rxMethod/signalMethodwith a signal outside an injection context, without an explicitinjector, is deprecated and will throw in a future version. It bites when a root-provided store's method is called from a component'sngOnInit. Pass{ injector: this.injector }. - State must be a record, not an array.
withState([])andsignalState([])are invalid; NgRx ships ESLint rules for exactly this. withComputedauto-wraps plain functions incomputed(). Both() => …andcomputed(() => …)work; don't double-wrap.watchStateis synchronous,getStateinside aneffectis coalesced. Undo/redo and storage sync need to see every intermediate value, so they needwatchState— an effect would only show the last value of the tick.- Combining two input-taking
signalStoreFeatures that declare no generics is a compile error. The workaround is a dummy generic:function withZ<_>() { … }. - Entity updaters are not interchangeable.
add*no-ops on an id collision,set*replaces,upsert*merges. Picking the wrong one produces silent data loss.
References
Read these on demand — they are not loaded until you need them.
| Read this | When |
references/store-composition.md | Authoring or reshaping a store: state, computed, props, methods, hooks, linked state, private members, state tracking |
references/async-and-rxjs.md | The store talks to HTTP or any async source; choosing or debugging rxMethod / signalMethod |
references/entity-management.md | State holds a keyed collection: withEntities, entityConfig, the updater catalogue |
references/custom-features.md | Logic repeats across stores; building a reusable signalStoreFeature |
references/testing.md | Writing or fixing store tests: TestBed, unprotected, mocking |
references/events-plugin.md | Event-based/redux-style state, or several stores reacting to one event |
references/recipes.md | Starting a new store, or wanting a known-good end-to-end shape |
references/api-reference.md | Unsure of a signature, an import path, or which entry point exports a symbol |
Beyond NgRx
For Angular questions that are not about state — components, zoneless, routing, the CLI — use the angular-cli MCP server (list_projects → get_best_practices → search_documentation → find_examples) rather than relying on memory.
NgRx's own ESLint rules (prefer-protected-state, enforce-type-call, signal-state-no-arrays-at-root-level, with-state-no-arrays-at-root-level, signal-store-feature-should-use-generic-type) are the machine-checkable form of the defaults above; recommend them when a project is adopting the library seriously.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

