ngrx-signals
@ngrx/signals state management for Angular 20+ using pure reactive patterns with signalStore, rxMethod, and computed signals. Use when implementing reactive state, creating stores, managing async operations, or building signal-based architecture. Replaces traditional NgRx with simpler, more performant signal-based approach.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
@ngrx/signals (v20) Skill
🎯 Summary
@ngrx/signals provides signal-based reactive state management for Angular 20+, enabling predictable, testable, and scalable reactive stores.
Designed for the NgRx 20 ecosystem with first-class Signal support.
🛠️ Installation
pnpm install @ngrx/signals@latest
# or
ng add @ngrx/signals
Ensure your project is upgraded to Angular v20 & NgRx v20.
🚀 Basic Usage
1️⃣ Create a SignalStore
Use signalStore(...) to define a store:
- Include
withStateto manage initial state - Use
withMethods/rxMethodto encapsulate logic - Signals automatically track dependencies and update UI
Example:
const CounterStore = signalStore(
withState({ count: 0 }),
withMethods((store) => ({
increment: () => patchState(store, (state) => ({
count: state.count + 1
}))
}))
);
🔄 Core Concepts
🧠 Signals & Reactivity
- Signals are callable getter functions
- Automatically track dependencies and trigger updates (OnPush friendly)
📦 State Management
- Use
signalStore+withStateto define readable/writable state -
patchStateupdates partial state - Derived signals (
computed) create derived state
🚦 Advanced Skills
🔹 Entity Management
- Use
@ngrx/signals/entitiesplugin - Methods:
addEntity,updateEntity,removeEntity, etc. - Enhanced collection management
🔹 Computed State
- Create derived signals when source signal changes
- Avoid manual effects/subscriptions
🧪 Testing Skills
- Use
@ngrx/signals/testingfor testing utilities - Makes stores easier to test with helper functions
⭐ Advanced Patterns
👩💻 Event-Driven Architecture
- Experimental Events plugin for Flux-style design
- Use with caution in production
📜 Interop with RxJS
- Optional RxJS interoperability
- Use
rxMethodfor async operations
📁 Recommended Project Structure
src/
├── app/
│ ├── stores/
│ │ ├── counter.store.ts # Single store
│ │ ├── users.store.ts # Entity store
│ │ └── index.ts # Exports
│ ├── features/
│ │ └── users/
│ │ ├── ui/
│ │ │ ├── user-list.component.ts
│ │ │ └── user-detail.component.ts
│ │ └── users.store.ts # Feature store
│ └── services/
│ └── api.service.ts
📚 Learning Path
- ➤ Learn Angular Signals fundamentals
- ➤ Install & initialize @ngrx/signals
- ➤ Build simple feature store
- ➤ Add entity management
- ➤ Use advanced patterns (Events, RxJS interop)
- ➤ Write tests using @ngrx/signals/testing
📝 Notes
- @ngrx/signals is evolving rapidly
- Events/Flux plugin is experimental
- Official docs: NgRx Signals API Reference
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!