ng-signal-store
Skill13 starsChanged 44 days agoMITView on GitHub
Manage genuinely shared, multi-consumer state with @ngrx/signals SignalStore (withState / withComputed / withMethods / withEntities / rxMethod). Use when state must be shared across several components or routes and the user mentions state management, shared state, a store, NgRx, or SignalStore. Guard – prefer a local signal() / computed() or a signals-based service first; reach for a store only when state is truly shared. If @ngrx/signals is not in package.json, installation is a gated, explicit step.
- Installs packages
In this repository34 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .junie/AGENTS.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- angular-developerSkill
- brainstormingSkill
- code-reviewSkill
- create-a-skillSkill
- create-e2e-testsSkill
- diagnosing-bugsSkill
- frontend-designSkill
- git-stack-rewriteSkill
- grill-meSkill
- grill-with-styleSkill
- handoverSkill
- implement-planSkill
- ng-accessibilitySkill
- ng-data-accessSkill
- ng-formsSkill
- ng-migrateSkill
- ng-performanceSkill
- ng-prototypeSkill
- ng-refactorSkill
- ng-review-architectureSkill
- ng-review-style-guideSkill
- ng-securitySkill
- ng-stylingSkill
- ng-testingSkill
- ng-verify-featureSkill
- spartanSkill
- test-driven-developmentSkill
- unslopSkill
- update-skills-directorySkill
- update-skillsSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 33
Anti-reach rule: Do not introduce a store to dodge two levels of prop-drilling, to hold one component's UI flags, or "for consistency".
- Very specific: line 43
Check package.json first: if @ngrx/signals is missing, install it explicitly, matching the Angular major (this repo is Angular 22):
- Very specific: line 52
Prefer pnpm exec ng add @ngrx/signals@latest when you want the schematic.
- Very specific: line 70
Feature-scoped instance: add to a component/route providers: [Store].
- Very specific: line 75
Read in templates as store.slice(), store.derived().
- Very specific: line 129
Store as a fetch layer: Don't re-implement HTTP in the store.
≈ “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
ng-signal-store
@ngrx/signals SignalStore is a declarative, Signal-native state container built from composable
features – withState, withComputed, withMethods, withEntities, rxMethod – and easy to
over-reach for. Most state is component-local; a store earns its keep only when state is
genuinely shared across many consumers. Pass the gate first, then install, then build.
1. The gate – do you actually need a store?
Walk the tree top to bottom and stop at the first match:
- State lives in and is used by one component →
signal()for state,computed()for derived values. This is the default and covers the majority of cases (the TypeScript style guide: signals for local component state). - A parent owns state a few children read/write → pass it down with
input()/output()/model(), or a small signals-based service (signals +computeds,providedIn: 'root'for app-wide, or component-providersfor a subtree). No store yet. - Fetching remote data →
resource()/rxResource()(perstyle-guide/style-guide.ts.md), owned by a data-access service – see ng-data-access. A store consumes that; it does not replace it. - State is genuinely shared by multiple, unrelated consumers (across routes/features), with coordinated updates, meaningful derived state, and side effects → SignalStore.
Anti-reach rule. Do not introduce a store to dodge two levels of prop-drilling, to hold one
component's UI flags, or "for consistency". A BehaviorSubject-service is never the answer
here – the signals-based service in step 2 replaces that pattern. This mirrors
ng-refactor's Step-4 stance: "SignalStore only if you truly need it."
Gate passed when you can name ≥2 independent consumers of the same state and why local signals or a signals service can't serve them.
2. Install (only after the gate)
Check package.json first: if @ngrx/signals is missing, install it explicitly, matching the Angular major
(this repo is Angular 22):
pnpm add @ngrx/signals
# add @ngrx/operators too if you use tapResponse in rxMethod:
pnpm add @ngrx/operatorsPrefer pnpm exec ng add @ngrx/signals@latest when you want the schematic. After install, confirm
the installed version's peerDependencies list @angular/core ^22 before continuing; if the
registry only offers an older major, stop and report rather than forcing an incompatible version.
3. Store anatomy
signalStore(...features) returns an injectable service. Compose it from features (verbatim
API per the official guide):
withState(initialState)– an object literal; each slice becomes aSignal, nested objects becomeDeepSignal. Update only viapatchState(store, partialOrUpdaterFn).withComputed(({ slice }) => ({ ... }))– derived signals. Derived state lives here, never duplicated intowithState.withMethods((store, dep = inject(Dep)) => ({ ... }))– updaters and side effects; runs in an injection context, soinject()works.
Scope – two choices:
- Feature-scoped instance: add to a component/route
providers: [Store]. Tied to that component's lifecycle, fresh per mount – for state shared within one feature subtree. - App-wide singleton:
signalStore({ providedIn: 'root' }, ...)– one shared instance, only for truly global state.
Read in templates as store.slice(), store.derived(); call store.method(arg).
4. Worked example
// counter-store.ts
import { computed } from '@angular/core';
import { patchState, signalStore, withComputed, withMethods, withState } from '@ngrx/signals';
type CounterState = { count: number; step: number };
const initialState: CounterState = { count: 0, step: 1 };
export const CounterStore = signalStore(
withState(initialState),
withComputed(({ count }) => ({
doubleCount: computed(() => count() * 2),
})),
withMethods((store) => ({
increment(): void {
patchState(store, ({ count, step }) => ({ count: count + step }));
},
setStep(step: number): void {
patchState(store, { step });
},
})),
);// counter.ts
import { Component, inject } from '@angular/core';
import { CounterStore } from './counter-store';
@Component({
selector: 'app-counter',
providers: [CounterStore], // feature-scoped instance
template: `
<p>{{ store.count() }} (x2 = {{ store.doubleCount() }})</p>
<button type="button" (click)="store.increment()">+{{ store.step() }}</button>
`,
})
export class Counter {
protected readonly store = inject(CounterStore);
}5. Anti-patterns
- God-store. One mega-store for unrelated domains. Prefer one focused store per domain; the docs recommend dedicated stores over multiple collections in one store.
- Derived state in
withState. Storing a value you can compute (count * 2, filtered lists) invites drift. Put it inwithComputed. - Component-local state in a store. UI toggles, hover flags, one-off form scratch →
signal()in the component, not the store. - Store as a fetch layer. Don't re-implement HTTP in the store; inject a data-access service
and drive it via
rxMethod/resource(see references + ng-data-access). - Reaching past the gate. Introducing a store to avoid prop-drilling or replace a
BehaviorSubjectservice.
6. Verify loop
pnpm build– types resolve, feature composition compiles.pnpm lint(--fix) +pnpm format.- A store vitest test:
TestBed.inject(Store), assert initial state, derived values, and method effects (public API only) – references/testing-stores.md and ng-testing.
Done when build + lint are green and a test exercises the store's public API.
References
- references/entities-and-rxmethod.md –
withEntities+ entity updaters, andrxMethodfor reactive side effects consuming ng-data-access. - references/testing-stores.md – TestBed setup, scopes,
unprotected, mocking dependencies, testingrxMethod.
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.

