re-reduced
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -10,4 +10,4 @@ export interface Action<T = void> { | ||
} | ||
export interface ActionHandlerMap<TState> { | ||
[key: string]: ActionHandler<any, TState>; | ||
export interface ActionReducerMap<TState> { | ||
[key: string]: ActionReducer<any, TState>; | ||
} | ||
@@ -18,6 +18,6 @@ export interface ActionCreator<TPayload = void> { | ||
type: string; | ||
reduce: <TState>(handler: ActionHandler<TPayload, TState>) => { | ||
[key: string]: ActionHandler<TPayload, TState>; | ||
reduce: <TState>(handler: ActionReducer<TPayload, TState>) => { | ||
[key: string]: ActionReducer<TPayload, TState>; | ||
}; | ||
} | ||
export declare type ActionHandler<TPayload, TState> = (p: TPayload, s: TState) => TState; | ||
export declare type ActionReducer<TPayload, TState> = (s: TState, p: TPayload) => TState; |
import { Reducer } from "redux"; | ||
import { ActionHandlerMap } from "./core"; | ||
import { ActionReducerMap } from "./core"; | ||
export interface ReducerConfig<TActions, TState> { | ||
@@ -8,6 +8,6 @@ actions: TActions; | ||
} | ||
export declare type ReducerFunctorFn<TActions, TState> = (config: ReducerConfig<TActions, TState>) => ActionHandlerMap<TState>; | ||
export declare type ReducerFunctorFn<TActions, TState> = (config: ReducerConfig<TActions, TState>) => ActionReducerMap<TState>; | ||
export declare type ReducerFunctor<TActions, TState> = Array<ReducerFunctorFn<TActions, TState>> | ReducerFunctorFn<TActions, TState>; | ||
export interface ReducerFactory<TActions, TState> { | ||
(config: ReducerConfig<TActions, TState>, customHandlers?: ActionHandlerMap<TState>): Reducer<TState>; | ||
(config: ReducerConfig<TActions, TState>, customHandlers?: ActionReducerMap<TState>): Reducer<TState>; | ||
functor: ReducerFunctor<TActions, TState>; | ||
@@ -26,3 +26,3 @@ } | ||
}) => ReducerConfig<TActions, TState>; | ||
export declare function handleActions<TState>(handlers: ActionHandlerMap<TState> | Array<ActionHandlerMap<TState>>, initialState: TState): Reducer<TState>; | ||
export declare function handleActions<TState>(handlers: ActionReducerMap<TState> | Array<ActionReducerMap<TState>>, initialState: TState): Reducer<TState>; | ||
export declare const createReducer: <TActions, TState>(functor: ReducerFunctor<TActions, TState>, defaultInitialState: TState) => ReducerFactory<TActions, TState>; |
@@ -12,5 +12,5 @@ "use strict"; | ||
return (state = initialState, action) => { | ||
const actionHandler = $handlers[action.type]; | ||
if (typeof actionHandler === "function") { | ||
return actionHandler(action.payload, state); | ||
const actionReducer = $handlers[action.type]; | ||
if (typeof actionReducer === "function") { | ||
return actionReducer(action.payload, state); | ||
} | ||
@@ -17,0 +17,0 @@ return state; |
{ | ||
"name": "re-reduced", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A utility toolbelt that reduces boilerplate from your react/redux app", | ||
@@ -39,2 +39,3 @@ "main": "lib/index.js", | ||
"@types/react-redux": "^6.0.9", | ||
"docz": "^0.12.5", | ||
"jest": "^23.6.0", | ||
@@ -41,0 +42,0 @@ "prettier": "^1.14.3", |
@@ -0,1 +1,4 @@ | ||
[![npm module](https://badge.fury.io/js/re-reduced.svg)](https://www.npmjs.org/package/re-reduced) | ||
![travis](https://travis-ci.org/alanrsoares/re-reduced.svg?branch=master) | ||
# Re-reduced | ||
@@ -19,6 +22,11 @@ | ||
```js | ||
interface ActionCreator<T = void> { | ||
interface ActionCreator<TPayload = void> { | ||
(): Action; | ||
(payload: T): Action<T>; | ||
(payload: TPayload): Action<TPayload>; | ||
type: string; | ||
reduce: <TState>( | ||
handler: ActionReducer<TPayload, TState> | ||
) => { | ||
[key: string]: ActionReducer<TPayload, TState> | ||
}; | ||
} | ||
@@ -37,13 +45,13 @@ ``` | ||
### ActionHandler<TPayload, TState> | ||
### ActionReducer<TPayload, TState> | ||
```js | ||
type ActionHandler<TPayload, TState> = (p: TPayload, s: TState) => TState; | ||
type ActionReducer<TPayload, TState> = (s: TState, p: TPayload) => TState; | ||
``` | ||
### ActionHandlerMap<TState> | ||
### ActionReducerMap<TState> | ||
```js | ||
interface ActionHandlerMap<TState> { | ||
[key: string]: ActionHandler<any, TState>; | ||
interface ActionReducerMap<TState> { | ||
[key: string]: ActionReducer<any, TState>; | ||
} | ||
@@ -50,0 +58,0 @@ ``` |
12106
19
65
10