riducers 1.0.6 → 1.0.7
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 +5 -2
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -138,6 +138,8 @@ function reducerBuilder(key: string, opts?: ReducerOpts) {
|
|
|
138
138
|
return (state: any, action: { type: string; payload?: any; sort?: (a: ModelObj, b: ModelObj) => number }) => {
|
|
139
139
|
let isList = opts && opts?.stateType === 'list';
|
|
140
140
|
let isMap = opts && opts?.stateType === 'map';
|
|
141
|
+
let initialState = opts?.initialState;
|
|
142
|
+
|
|
141
143
|
if (state === undefined) {
|
|
142
144
|
if (opts && opts?.initialState !== undefined) return opts?.initialState;
|
|
143
145
|
else if (isList) return [];
|
|
@@ -164,7 +166,7 @@ function reducerBuilder(key: string, opts?: ReducerOpts) {
|
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
|
|
167
|
-
let sort = action.sort
|
|
169
|
+
let sort = action.sort ?? opts?.sort;
|
|
168
170
|
if (op === "insert") {
|
|
169
171
|
if (isList && payload) return listInsertReducer(state, {payload, sort, keyName});
|
|
170
172
|
else if (isMap && payload) return mapInsertReducer(state, {payload, keyName});
|
|
@@ -178,7 +180,8 @@ function reducerBuilder(key: string, opts?: ReducerOpts) {
|
|
|
178
180
|
else if (isMap) return mapDeleteReducer(state, {payload, keyName});
|
|
179
181
|
return objDeleteReducer();
|
|
180
182
|
} else if (op === "clear") {
|
|
181
|
-
|
|
183
|
+
console.log('initialState', initialState)
|
|
184
|
+
if (initialState !== undefined) return initialState;
|
|
182
185
|
if (isList) return listClearReducer()
|
|
183
186
|
else if (isMap) return mapClearReducer();
|
|
184
187
|
return objClearReducer();
|