Comparing version 0.6.0 to 0.6.1
{ | ||
"name": "redux-ease", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Reduce Redux boilerplate with ease", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -16,3 +16,4 @@ import { getActionCreator, getReducerBuilder } from '../src' | ||
const reducer = getReducerBuilder(initialState).copyState() | ||
const reducer = getReducerBuilder(initialState) | ||
.copyState() | ||
.handle(multiply, (s, a) => ({ value: s.value * a.payload.multiplier })) | ||
@@ -24,2 +25,25 @@ .build() | ||
it('should create action with multiple args', () => { | ||
const actionBuilder = getActionCreator('TEST', '/') | ||
const initialState = { | ||
value: 'Hello' | ||
} | ||
const addString = actionBuilder.build('ADD_STRING', (content: string, times: number = 1) => ({ content, times })) | ||
const reducer = getReducerBuilder(initialState) | ||
.copyState() | ||
.handle(addString, (s, a) => { | ||
let value = s.value | ||
for (let i = 0; i < a.payload.times; i++) { | ||
value += ' ' + a.payload.content | ||
} | ||
return { value } | ||
}) | ||
.build() | ||
expect(reducer(undefined, addString('World', 3)).value).toEqual('Hello World World World') | ||
}) | ||
it('should extend action', () => { | ||
@@ -38,3 +62,4 @@ const actionBuilder = getActionCreator('TEST') | ||
const reducer = getReducerBuilder(initialState).copyState() | ||
const reducer = getReducerBuilder(initialState) | ||
.copyState() | ||
.handle(multiply, (s, a) => ({ value: s.value * a.payload.multiplier })) | ||
@@ -41,0 +66,0 @@ .build() |
@@ -1,2 +0,2 @@ | ||
import { TOptionalPayloadAction, TDynamicExportedActionCreator, TExportedActionCreator, TActionPayloadCreator } from "./types"; | ||
import { TOptionalPayloadAction, TDynamicExportedActionCreator, TExportedActionCreator, TActionPayloadCreator, TArgs } from "./types"; | ||
@@ -8,7 +8,7 @@ export interface IActionCreatorBuilder { | ||
build <A, P> (actionTypeCode: string, creator: (...args: A[]) => P): TExportedActionCreator<A, P> | ||
build <A extends TArgs, P> (actionTypeCode: string, creator: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P> | ||
extend <A, P> (action: TExportedActionCreator<any, P>, creator: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P> | ||
extend <A extends TArgs, P> (action: TExportedActionCreator<any, P>, creator: TActionPayloadCreator<A, P>): TExportedActionCreator<A, P> | ||
buildDynamic <A, P = any> (creator: (...args: A[]) => TOptionalPayloadAction<P>): TDynamicExportedActionCreator<A, P> | ||
buildDynamic <A extends TArgs, P = any> (creator: (...args: A) => TOptionalPayloadAction<P>): TDynamicExportedActionCreator<A, P> | ||
} |
@@ -1,23 +0,25 @@ | ||
export interface TActionCreator <A = any, P = any> { | ||
(actionTypeCode: string, creator: (...args: A[]) => P): TExportedActionCreator<A, P> | ||
export interface TActionCreator <A extends TArgs = any, P = any> { | ||
(actionTypeCode: string, creator: (...args: A) => P): TExportedActionCreator<A, P> | ||
appendToTypeCode?: string | ||
} | ||
export interface TActionPayloadCreator <A, P> { | ||
(...args: A[]): P | ||
export interface TActionPayloadCreator <A extends TArgs, P> { | ||
(...args: A): P | ||
} | ||
export interface TGetActionCreator <A = any[], P = any> { | ||
export interface TGetActionCreator <A extends TArgs = any[], P = any> { | ||
(reducerCode?: string, joinSymbol?: string): TActionCreator<A, P> | ||
} | ||
export interface TExportedActionCreator <A, P> { | ||
(...args: A[]): TAction<P> | ||
export interface TExportedActionCreator <A extends TArgs, P> { | ||
(...args: A): TAction<P> | ||
typeCode: string | ||
} | ||
export interface TDynamicExportedActionCreator <A, P> { | ||
(...args: A[]): TOptionalPayloadAction<P> | ||
export interface TDynamicExportedActionCreator <A extends TArgs, P> { | ||
(...args: A): TOptionalPayloadAction<P> | ||
} | ||
export type TArgs <T = any> = T[] | ||
export interface TOptionalPayloadAction <P = any> { | ||
@@ -24,0 +26,0 @@ type: string, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172469
411