RxJS powered state management for Angular applications, inspired by Redux
RxJS powered state management for Angular applications, inspired by Redux
RxJS powered state management for Angular applications, inspired by Redux @ngrx/store is a controlled state container designed to help write performant, consistent applications on top of Angular. Core tenets:
Store, an observable of state and an observer of actionsThese core principles enable building components that can use the OnPush change detection strategy
giving you intelligent, performant change detection
throughout your application.
Install @ngrx/core and @ngrx/store from npm:
npm install @ngrx/core @ngrx/[email protected] --saveOptional packages:
Create a reducer function for each data type you have in your application. The combination of these reducers will make up your application state:
// counter.ts
import { ActionReducer, Action } from '@ngrx/store';
export const INCREMENT = 'INCREMENT';
export const DECREMENT = 'DECREMENT';
export const RESET = 'RESET';
export function counterReducer(state: number = 0, action: Action) {
switch (action.type) {
case INCREMENT:
return state + 1;
case DECREMENT:
return state - 1;
case RESET:
return 0;
default:
return state;
}
}In your app's main module, import those reducers and use the StoreModule.provideStore(reducers)
function to provide them to Angular's injector:
import { NgModule } from '@angular/core'
import { StoreModule } from '@ngrx/store';
import { counterReducer } from './counter';
@NgModule({
imports: [
BrowserModule,
StoreModule.provideStore({ counter: counterReducer })
]
})
export class AppModule {}You can then inject the Store service into your components and services. Use store.select to
select slice(s) of state:
…Please read contributing guidelines here.
No open issues yet, or sync has not completed.