Skip to content

Commit

Permalink
#68 Generic clear reducer.
Browse files Browse the repository at this point in the history
  • Loading branch information
artzub committed Feb 3, 2022
1 parent 67c7c0e commit bbc17e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/redux/modules/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,5 @@ export default createSlice({
toggle: (state, { payload }) => {
state.show = payload ?? !state.show;
},

clear() {
return {
...initialState,
};
},
},
});
5 changes: 5 additions & 0 deletions src/redux/utils/createSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const wrapWithNamespace = (cancelType, module) => {
};
};

const clearState = (initialState) => () => {
return initialState;
};

/**
Function to create a redux "duck" module by reusing redux toolkit's
createSlice. Motivation behind "duck" is to reduce unnecessary redux
Expand Down Expand Up @@ -99,6 +103,7 @@ export const createSlice = ({ sagas, reducers, selectors, ...sliceOpts }) => {
reducers: {
...(reducers || {}),
cancel: reducers?.cancel || stateIdentity,
clear: reducers?.clear || clearState(sliceOpts.initialState ?? {}),
},
};

Expand Down

0 comments on commit bbc17e3

Please sign in to comment.