NGRX FrameWork For Angular (@ngrxstore)
NGRX FrameWork For Angular (@ngrxstore)
you might use NgRx when you build an application with a lot of user interactions and
multiple data sources, when managing state in services are no longer sufficient.
SHARI principle:
Installation
ng add @ngrx/store
Diagram:
The following diagram represents the overall general flow of application state in NgRx.
We have three main concepts in above architecture :
1. Actions
2. Reducers
The reducer function
● Defining the state shape
● Setting the initial state
● Creating the reducer function
Registering root state
Register feature state
3.Selectors
Using a selector for one piece of state
Using selectors for multiple pieces of state
Using selectors with props
Selecting Feature States
Resetting Memoized Selectors
Using Store Without Type Generic
4.Meta-reducers
Using a meta-reducer to log all actions
Using Dependency Injection:
Injecting Reducers:
To inject the root reducers into your application, use an InjectionToken and a Provider to
register the reducers through dependency injection.
Injecting Meta-Reducers:
To inject the feature store configuration into your module, use an InjectionToken and a
Provider to register the feature config object through dependency injection.
If you want to dispatch an action or select some slice of your store state, you will need
to downgrade the Store service to use it in the AngularJS parts of your application.
Runtime checks:
@ngrx/store ships with five (5) built-in runtime checks:
● Default On:
● Default Off:
NgZone
unique