ok-ngrx-tools
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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>,
	},
]

Readme

Keywords

none

Package Sidebar

Install

npm i ok-ngrx-tools

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

47.3 kB

Total Files

50

Last publish

Collaborators

  • ondrakoupil