bobflux
Version:
Bobflux is pure functional implementation of FLUX architecture.
25 lines (22 loc) • 883 B
text/typescript
import * as f from "../../index";
export * from "../../index";
export const createUpdateAction = <TState extends f.IState | undefined, TParams extends {}>(
cursor: f.ICursor<TState> | f.ICursorFactory<TState, TParams>,
postHandler?: (state: TState, params?: TParams) => TState
) =>
f.createAction<TState, TParams>(cursor, (state: TState, params: TParams) => {
return postHandler
? postHandler(
f.shallowCopy(state, (l) => {
Object.keys(params).forEach((p) => {
(<any>l)[p] = (<any>params)[p];
});
}),
params
)
: f.shallowCopy(state, (l) => {
Object.keys(params).forEach((p) => {
(<any>l)[p] = (<any>params)[p];
});
});
});