Skip to content

Commit

Permalink
types: add subscribe options type (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking authored Apr 23, 2020
1 parent 38c11dc commit e2b9974
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export declare class Store<S> {
dispatch: Dispatch;
commit: Commit;

subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any): () => void;
subscribeAction<P extends ActionPayload>(fn: SubscribeActionOptions<P, S>): () => void;
subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any, options?: SubscribeOptions): () => void;
subscribeAction<P extends ActionPayload>(fn: SubscribeActionOptions<P, S>, options?: SubscribeOptions): () => void;
watch<T>(getter: (state: S, getters: any) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void;

registerModule<T>(path: string, module: Module<T, S>, options?: ModuleOptions): void;
Expand Down Expand Up @@ -72,6 +72,10 @@ export interface ActionPayload extends Payload {
payload: any;
}

export interface SubscribeOptions {
prepend?: boolean
}

export type ActionSubscriber<P, S> = (action: P, state: S) => any;

export interface ActionSubscribersObject<P, S> {
Expand Down
4 changes: 4 additions & 0 deletions types/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace StoreInstance {
state.value;
});

store.subscribe(() => {}, { prepend: true });

store.subscribeAction((action, state) => {
action.type;
action.payload;
Expand Down Expand Up @@ -74,6 +76,8 @@ namespace StoreInstance {
}
});

store.subscribeAction({}, { prepend: true });

store.replaceState({ value: 10 });
}

Expand Down

0 comments on commit e2b9974

Please sign in to comment.