Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Add generic for store state type (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanterreJo committed May 7, 2020
1 parent 926dba3 commit 8f500f6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ interface Storage {
removeItem: (key: string) => void;
}

interface Options {
interface Options<State> {
key?: string;
paths?: string[];
reducer?: (state: any, paths: string[]) => object;
subscriber?: (
store: typeof Store
store: Store<State>
) => (handler: (mutation: any, state: any) => void) => void;
storage?: Storage;
getState?: (key: string, storage: Storage) => any;
setState?: (key: string, state: typeof Store, storage: Storage) => void;
setState?: (key: string, state: Store<State>, storage: Storage) => void;
filter?: (mutation: MutationPayload) => boolean;
arrayMerger?: (state: any, saved: any) => any;
rehydrated?: (store: typeof Store) => void;
rehydrated?: (store: Store<State>) => void;
fetchBeforeUse?: boolean;
overwrite?: boolean;
assertStorage?: (storage: Storage) => void | Error;
}

export default function (options?: Options) {
export default function <State>(
options?: Options<State>
): (store: Store<State>) => void {
options = options || {};

const storage = options.storage || (window && window.localStorage);
Expand Down

0 comments on commit 8f500f6

Please sign in to comment.