immer-reducer
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -39,3 +39,3 @@ "use strict"; | ||
return { | ||
type: PREFIX + ":" + key, | ||
type: PREFIX + ":" + immerReducerClass.name + "#" + key, | ||
payload: args, | ||
@@ -56,6 +56,9 @@ }; | ||
} | ||
var methodKey = removePrefix(action.type); | ||
if (typeof immerReducerClass.prototype[methodKey] !== "function") { | ||
var _a = removePrefix(action.type).split("#"), className = _a[0], methodName = _a[1]; | ||
if (className !== immerReducerClass.name) { | ||
return state; | ||
} | ||
if (typeof immerReducerClass.prototype[methodName] !== "function") { | ||
return state; | ||
} | ||
if (!state) { | ||
@@ -66,3 +69,3 @@ throw new Error("ImmerReducer does not support undefined state. Pass initial state to createReducerFunction() or createStore()"); | ||
var reducers = new immerReducerClass(draftState, state); | ||
reducers[methodKey].apply(reducers, action.payload); | ||
reducers[methodName].apply(reducers, action.payload); | ||
return draftState; | ||
@@ -69,0 +72,0 @@ }); |
{ | ||
"name": "immer-reducer", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/immer-reducer.js", |
@@ -9,2 +9,4 @@ # Immer Reducer | ||
Read an introductory [blog post here](https://medium.com/@esamatti/type-safe-boilerplate-free-redux-906844ec6325). | ||
## Install | ||
@@ -23,3 +25,2 @@ | ||
class MyImmerReducer extends ImmerReducer { | ||
// each method becomes an Action Creator | ||
@@ -80,7 +81,7 @@ setFirstName(firstName) { | ||
{ | ||
type: "IMMER_REDUCER:setFirstName", | ||
type: "IMMER_REDUCER:MyImmerReducer#setFirstName", | ||
payload: ["Charlie"], | ||
} | ||
{ | ||
type: "IMMER_REDUCER:setLastName", | ||
type: "IMMER_REDUCER:MyImmerReducer#setLastName", | ||
payload: ["Brown"], | ||
@@ -157,6 +158,6 @@ } | ||
## Type Safe connect()? | ||
## Examples | ||
If you enjoy this then also checkout | ||
[redux-render-prop](https://github.com/epeli/redux-render-prop) for type safe | ||
`connect()` alternative. | ||
Here's a more complete example with [redux-render-prop](https://github.com/epeli/redux-render-prop): | ||
<https://github.com/epeli/typescript-redux-todoapp> |
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
13397
6
123
160
1