immer-reducer
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -34,3 +34,3 @@ import { Draft } from "immer"; | ||
interface ImmerReducerFunction<T extends ImmerReducerClass> { | ||
(state: ImmerReducerState<T> | undefined, action: ReturnTypeUnion<ActionCreators<T>>): ImmerReducerState<T> | undefined; | ||
(state: ImmerReducerState<T> | undefined, action: ReturnTypeUnion<ActionCreators<T>>): ImmerReducerState<T>; | ||
} | ||
@@ -51,3 +51,3 @@ /** generate ActionCreators types from the ImmerReducer class */ | ||
export declare function createActionCreators<T extends ImmerReducerClass>(immerReducerClass: T): ActionCreators<T>; | ||
export declare function createReducerFunction<T extends ImmerReducerClass>(immerReducerClass: T): ImmerReducerFunction<T>; | ||
export declare function createReducerFunction<T extends ImmerReducerClass>(immerReducerClass: T, initialState?: ImmerReducerState<T>): ImmerReducerFunction<T>; | ||
export {}; |
@@ -47,4 +47,7 @@ "use strict"; | ||
exports.createActionCreators = createActionCreators; | ||
function createReducerFunction(immerReducerClass) { | ||
function createReducerFunction(immerReducerClass, initialState) { | ||
return function immerReducerFunction(state, action) { | ||
if (state === undefined) { | ||
state = initialState; | ||
} | ||
if (!action.type.startsWith(PREFIX + ":")) { | ||
@@ -58,3 +61,3 @@ return state; | ||
if (!state) { | ||
throw new Error("ImmerReducer does not support undefined state. Pass initial state to createStore()"); | ||
throw new Error("ImmerReducer does not support undefined state. Pass initial state to createReducerFunction() or createStore()"); | ||
} | ||
@@ -61,0 +64,0 @@ return immer_1.default(state, function (draftState) { |
{ | ||
"name": "immer-reducer", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/immer-reducer.js", |
Sorry, the diff of this file is not supported yet
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
11938
120