Skip to content

Commit

Permalink
Improve generics - types are now passed to the returned reducer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zewish committed Jun 1, 2021
1 parent c505fd6 commit 0c3d549
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
@@ -1,4 +1,4 @@
import { Action, PreloadedState, Reducer, StoreCreator, StoreEnhancer } from 'redux';
import { Action, AnyAction, PreloadedState, Reducer, StoreCreator, StoreEnhancer } from 'redux';
declare const REMEMBER_REHYDRATED = "@@REMEMBER_REHYDRATED";
declare const REMEMBER_PERSISTED = "@@REMEMBER_PERSISTED";
type SerializeFunction = (data: any) => any;
Expand All @@ -14,6 +14,6 @@ type Options = {
persistThrottle: number;
persistWholeStore: boolean;
};
declare const rememberReducer: (reducers: Reducer) => Reducer;
declare const rememberReducer: <S = any, A extends Action<any> = AnyAction>(reducers: Reducer<S, A>) => Reducer<S, A>;
declare const rememberEnhancer: <S, A extends Action<any>, Ext>(driver: Driver, rememberedKeys: string[], { prefix, serialize, unserialize, persistThrottle, persistWholeStore }?: Partial<Options>) => (createStore: StoreCreator) => (rootReducer: Reducer<S, A>, initialState?: PreloadedState<S> | undefined, enhancer?: StoreEnhancer<Ext, {}> | undefined) => import("redux").Store<S, A> & Ext;
export { rememberReducer, rememberEnhancer, REMEMBER_REHYDRATED, REMEMBER_PERSISTED };
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "redux-remember",
"version": "2.1.1",
"version": "2.1.2",
"description": "Saves and loads your redux state from a key-value store of your choice",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Expand Up @@ -10,12 +10,14 @@ import {
StoreEnhancer
} from 'redux';

const rememberReducer = (reducers: Reducer): Reducer => {
const data = {
const rememberReducer = <S = any, A extends Action = AnyAction>(
reducers: Reducer<S, A>
): Reducer<S, A> => {
const data: any = {
state: {}
};

return (state = data.state, action: AnyAction) => {
return (state: S = data.state, action: any) => {
if (action.type && (
action.type === '@@INIT'
|| action.type.startsWith('@@redux/INIT')
Expand All @@ -30,7 +32,7 @@ const rememberReducer = (reducers: Reducer): Reducer => {
...data.state,
...(action.payload || {})
},
{ type: REMEMBER_REHYDRATED }
{ type: REMEMBER_REHYDRATED } as any
);

return data.state;
Expand Down

0 comments on commit 0c3d549

Please sign in to comment.