diff --git a/src/buildUpreducer/index.js b/src/buildUpreducer/index.js deleted file mode 100644 index 52724f6..0000000 --- a/src/buildUpreducer/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import fp from 'lodash/fp'; - -export default function buildUpreducer(initial, mutations) { - return (action = {}) => (state) => { - if (state === null) state = initial; - - const a = - mutations[(action).type] || - mutations['*']; - - if(!a) return state; - - return a((action).payload, action)(state); - }; -} diff --git a/src/buildUpreducer/index.ts b/src/buildUpreducer/index.ts new file mode 100644 index 0000000..bedc8b2 --- /dev/null +++ b/src/buildUpreducer/index.ts @@ -0,0 +1,19 @@ +import fp from 'lodash/fp'; + +import { Dictionary, Mutation, UpduxAction } from '../types'; + +function buildUpreducer(initial: S, mutations: Dictionary> ) { + return (action :UpduxAction) => (state: S) => { + if (state === null) state = initial; + + const a = + mutations[action.type] || + mutations['*']; + + if(!a) return state; + + return a(action.payload, action)(state); + }; +} + +export default buildUpreducer; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..414d299 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,10 @@ +import { Action } from 'redux'; + +export type UpduxAction = Action & Partial<{ + payload: any, + meta: any, +}> + +export type Dictionary = { [key: string]: T }; + +export type Mutation = (payload: any, action: Action) => (state: S) => S ;