ok-ngrx-tools
v1.2.0
Published
My personal JS tools and utilities for working with NGRX
Downloads
3
Readme
Set of useful tools for NGRX
This is my personal set of various JS tools I use in my projects with Angular and NGRX.
Feel free to use them, but please keep in mind that I guarantee nothing.
Reducer function tools
Array-based tools
- withItemInArrayReplaced, withItemInArrayUpdated
- withoutItem, withoutId, withoutItemAtIndex
- also versions of functions above that works with several items at once
Entity store tools
- data loading actions, selectors and effect functions
Hydration
Usage:
app.module.ts:
import {
HydrationEffects,
hydrationMetaReducer,
HydrationParams,
HydrationParamsDiToken,
} from 'ok-ngrx-tools';
imports: [
//... various imports
StoreModule.forRoot({
// ... various reducers
}, {
metaReducers: [
hydrationMetaReducer,
],
}),
EffectsModule.forRoot([
// ... various other effects
HydrationEffects,
]),
]
providers: [
// Various other providers
{
provide: HydrationParamsDiToken,
useValue: {
storageKey: 'name-in-storage',
storageTtlSeconds: 60 * 120, // How many seconds can be hydrated state considered valid? I.e. TTL cache
// Optional functions to transform state before saving to storage / loading from storage to state
// Useful for recreation non-serializable data like Date objects etc.
// or to remove data that is not intended for saving to storage.
stateToStoredDataProcessor: (state: AppStateType) => Promise<any>;
storedDataToStateProcessor: (data: any) => Promise<AppStateType>;
// Optionally, state can be resetted and hydration disabled if a query parameter is present
// Pass either a part of query string, or a RegExp
resetParameter: 'reset=1'
} as HydrationParams<AppState>,
},
]