re-reduced
Advanced tools
Comparing version 0.9.0 to 0.10.0
import { ActionCreator, AsyncAction } from "./core"; | ||
export declare function createAction<TPayload, TMeta = any>(type: string): ActionCreator<TPayload, TMeta>; | ||
export declare function createAsyncAction<TRun, TSuccess>(type: string, domain: string): AsyncAction<TRun, TSuccess, Error>; | ||
export declare function createAsyncAction<TRun, TSuccess, TFailure = Error>(type: string, domain: string): AsyncAction<TRun, TSuccess, TFailure>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createAction(type) { | ||
const actionCreator = ((payload, meta) => ({ | ||
meta, | ||
const actionCreator = ((payload, options) => ({ | ||
error: typeof options !== "undefined" ? options.error : undefined, | ||
meta: typeof options !== "undefined" ? options.meta : undefined, | ||
payload, | ||
@@ -17,8 +18,8 @@ type | ||
function createAsyncAction(type, domain) { | ||
const fn = createAction(`${domain}/${type}`); | ||
fn.request = createAction(`${domain}/${type}_REQUEST`); | ||
fn.success = createAction(`${domain}/${type}_SUCCESS`); | ||
fn.failure = createAction(`${domain}/${type}_FAILURE`); | ||
return fn; | ||
const asyncAction = createAction(`${domain}/${type}`); | ||
asyncAction.request = createAction(`${domain}/${type}_REQUEST`); | ||
asyncAction.success = createAction(`${domain}/${type}_SUCCESS`); | ||
asyncAction.failure = createAction(`${domain}/${type}_FAILURE`); | ||
return asyncAction; | ||
} | ||
exports.createAsyncAction = createAsyncAction; |
@@ -5,2 +5,3 @@ export interface Action<T = void, TMeta = any> { | ||
meta?: TMeta; | ||
error?: boolean; | ||
} | ||
@@ -15,5 +16,10 @@ export interface AsyncAction<TRun, TSuccess, TError = Error> extends ActionCreator<TRun> { | ||
} | ||
export interface ActionCreatorOptions<TMeta> { | ||
meta?: TMeta; | ||
error?: boolean; | ||
} | ||
export interface ActionCreator<TPayload = void, TMeta = any> { | ||
(): Action; | ||
(payload: TPayload, meta?: TMeta): Action<TPayload, TMeta>; | ||
(options?: ActionCreatorOptions<TMeta>): Action<any, TMeta>; | ||
(payload: TPayload, options?: ActionCreatorOptions<TMeta>): Action<TPayload, TMeta>; | ||
type: string; | ||
@@ -20,0 +26,0 @@ reduce: <TState>(reducer: ActionReducer<TState, TPayload>) => { |
@@ -12,3 +12,3 @@ "use strict"; | ||
catch (e) { | ||
yield effects_1.put(asyncAction.failure(e)); | ||
yield effects_1.put(asyncAction.failure(e, { error: true })); | ||
} | ||
@@ -15,0 +15,0 @@ }; |
{ | ||
"name": "re-reduced", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "A utility toolbelt that reduces boilerplate from your react/redux app", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
109525
460