Gathering detailed insights and metrics for @spaf/ngrx-orchestrator
Gathering detailed insights and metrics for @spaf/ngrx-orchestrator
Gathering detailed insights and metrics for @spaf/ngrx-orchestrator
Gathering detailed insights and metrics for @spaf/ngrx-orchestrator
npm install @spaf/ngrx-orchestrator
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
1 Stars
2 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Apr 15, 2024
Latest Version
1.0.2
Package Id
@spaf/ngrx-orchestrator@1.0.2
Unpacked Size
35.45 kB
Size
6.74 kB
File Count
8
NPM Version
10.5.0
Node Version
18.17.0
Published on
Apr 14, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
3
A Powerful State Management Toolkit for Angular
The library is in early development!
NgRxOrchestrator is a comprehensive toolkit designed to streamline the management of application state in Angular projects using the Redux pattern with NgRx. By integrating immer for immutable state transformations, NgRxOrchestrator simplifies the creation and handling of action-driven state changes, enhancing the readability and maintainability of your code. This library provides a set of utilities that automate the boilerplate of setting up and managing state flows, including loading, success, and error handling for asynchronous operations. Whether you are building a complex enterprise-level application or a simple interactive interface, NgRxOrchestrator helps you implement a clean, scalable, and efficient state management architecture.
NgRxOrchestrator depends on @ngrx/store and immer
1createDataFlowActions<Input, Result>( 2 { 3 source: 'Source', 4 action: 'Action description' 5 } 6)
createDataFlowActions
returns an object containing 4 actions: { load, loadSuccess, loadFailure, reset }
The Input
type is used as prop on the load
action
The Result
type is used as prop on the loadSuccess
action
In your someState.actions.ts
After | Before |
---|---|
|
|
someState.reducer.ts
1export interface SomeState { 2 details: { 3 data: DummyObject 4 // You need to add loading and errors properties 5 // in your state definition to be able to select them 6 loading: boolean 7 errors: any[], 8 }; 9} 10 11export const initialState: SomeState = { 12 details: { 13 data : null, 14 loading: false, 15 errors : [] 16 }, 17}
1export const reducer = createReducer( 2 initialState,
After | Before |
---|---|
|
|
1onActionGroup( 2 actionGroup, 3 dataPathFromState, 4 initialState, 5 reducerFunction ? 6)
onActionGroup
returns an array containing 4 ons to be used in the reducer:
[ onLoad, onLoadSuccess, onLoadFailure, onReset ]
onActionGroup
by default sets the result of its loadSuccess
action in the dataPathFromState
property of your state
[!IMPORTANT] You can pass a fourth parameter to
onActionGroup
for sophisticated state updates
You can use immer's
produce
function to handle the state update:
1onActionGroup( deleteSomeData, 2 'list.data', 3 initialState, 4 (state, deletedId) => 5 produce( state, draft => { 6 draft.list.data = draft.list.data.filter( d => d.id!=deletedId ); 7 } 8 ) 9)
Or by manually destructuring and updating the state:
1onActionGroup( deleteSomeData, 2 'list.data', 3 initialState, 4 (state, deletedId) => ( 5 { 6 ...state, 7 list: { 8 ...state.list, 9 data: state.list.data.filter( d => d.id!=deletedId ) 10 } 11 } 12 ) 13)
1this.store.dispatch( loadSomeStateDetails.load( { param: id } ) );
someState.selectors.ts
(Selectors remain unchanged)1export const someStateDetails = createSelector(
2 selectSomeState,
3 // You need to select the whole object containing
4 // your data, loading and errors if you want to use the loading and errors properties
5 (state: SomeState) => state.details
6);
1data$ = this.store.select( someStateDetails ); 2// data$ Is an Observable of your data, errors and loading
No vulnerabilities found.
No security vulnerabilities found.