buildActions => ts

typescript
Yanick Champoux 2019-10-23 13:57:40 -04:00
parent d9bac9dd7d
commit ca89c53c0b
3 changed files with 18 additions and 12 deletions

View File

@ -1,8 +1,14 @@
import fp from 'lodash/fp';
import { Action } from '../types';
function actionFor(type) {
const creator = ( (payload = undefined, meta = undefined) =>
fp.pickBy(v => v !== undefined)({type, payload, meta})
interface ActionCreator {
( ...args: any[] ): Action;
_genericAction?: boolean
}
function actionFor(type:string) {
const creator : ActionCreator = ( (payload = undefined, meta = undefined) =>
fp.pickBy(v => v !== undefined)({type, payload, meta}) as Action
);
creator._genericAction = true;
@ -11,7 +17,7 @@ function actionFor(type) {
}
export default function buildActions(
creators = {},
creators : { [action: string]: Function } = {},
mutations = {},
effects = {},
subActions = [],
@ -31,7 +37,7 @@ export default function buildActions(
...generic,
...crafted,
...Object.entries(creators).map(
([type, payload]) => [type, (...args) => ({ type, payload: payload(...args) })]
([type, payload]: [ string, Function ]) => [type, (...args: any) => ({ type, payload: payload(...args) })]
),
];

View File

@ -1,9 +1,9 @@
import fp from 'lodash/fp';
import { Dictionary, Mutation, UpduxAction } from '../types';
import { Dictionary, Mutation, Action } from '../types';
function buildUpreducer<S>(initial: S, mutations: Dictionary<Mutation<S>> ) {
return (action :UpduxAction) => (state: S) => {
return (action :Action) => (state: S) => {
if (state === null) state = initial;
const a =

View File

@ -1,9 +1,9 @@
import { Action } from 'redux';
export type UpduxAction = Action & Partial<{
payload: any,
meta: any,
}>
export type Action = {
type: string,
payload?: any,
meta?: any,
}
export type Dictionary<T> = { [key: string]: T };