Skip to main content

Actions

Share your state changes with actions.

You can create actions for state changes in the ngrx-lite/component-store or for state changes made by a loadingEffect in the ngrx-lite/loading-store.

Every action the library dispatches is typed [COMPONENT_STORE][<storeName>] <actionName>, which is how the local state becomes visible in the global store and the DevTools.

getCustomAction​

warning

This method does not support the lazy functional ngrx-lite/component-store. For lazy functional stores use getCustomActionWithDynamicStore.

Get an action for a ngrx-lite/component-store or ngrx-lite/loading-store.

effect.action.ts
import { getCustomAction } from '@gernsdorfer/ngrx-lite';

const myEffectAction = getCustomAction<{ counter: number }>({
storeName: 'storeName',
actionName: 'myAction',
});

getCustomActionWithDynamicStore​

Get an action for a lazy functional ngrx-lite/component-store.

effect.action.ts
import { getCustomActionWithDynamicStore } from '@gernsdorfer/ngrx-lite';

const myEffectAction = getCustomActionWithDynamicStore<'StoreA'>({
storeName: 'storeName',
dynamicStoreName: 'StoreA',
actionName: 'myAction',
});

getEffectAction​

Get an action for a loadingEffect — one of LOAD, SUCCESS or ERROR — in the ngrx-lite/loading-store.

effect.action.ts
import { EffectStates, getEffectAction } from '@gernsdorfer/ngrx-lite';

const myEffectAction = getEffectAction({
storeName: 'storeName',
effectName: 'incrementEffectName',
dynamicStoreName: 'StoreA',
type: EffectStates.SUCCESS,
});

EffectStates is exported by the library:

enum EffectStates {
LOAD = 'LOAD',
SUCCESS = 'SUCCESS',
ERROR = 'ERROR',
}