riducers 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +2 -3
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -141,7 +141,7 @@ function reducerBuilder(key: string, opts?: ReducerOpts) {
|
|
|
141
141
|
let initialState = opts?.initialState;
|
|
142
142
|
|
|
143
143
|
if (state === undefined) {
|
|
144
|
-
if (opts
|
|
144
|
+
if (opts?.initialState !== undefined) return opts?.initialState;
|
|
145
145
|
else if (isList) return [];
|
|
146
146
|
else if (isMap) return {};
|
|
147
147
|
else return null;
|
|
@@ -152,7 +152,7 @@ function reducerBuilder(key: string, opts?: ReducerOpts) {
|
|
|
152
152
|
|
|
153
153
|
let op = m[1];
|
|
154
154
|
let payload = action.payload;
|
|
155
|
-
let keyName =
|
|
155
|
+
let keyName = opts?.keyName ?? "id";
|
|
156
156
|
|
|
157
157
|
if (isMap && !OPS.includes(op)) {
|
|
158
158
|
if (payload && !Array.isArray(payload)) {
|
|
@@ -180,7 +180,6 @@ function reducerBuilder(key: string, opts?: ReducerOpts) {
|
|
|
180
180
|
else if (isMap) return mapDeleteReducer(state, {payload, keyName});
|
|
181
181
|
return objDeleteReducer();
|
|
182
182
|
} else if (op === "clear") {
|
|
183
|
-
console.log('initialState', initialState)
|
|
184
183
|
if (initialState !== undefined) return initialState;
|
|
185
184
|
if (isList) return listClearReducer()
|
|
186
185
|
else if (isMap) return mapClearReducer();
|