index.d.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import './vue'
  2. export class Store<S> {
  3. constructor(options: StoreOption<S>);
  4. state: S;
  5. dispatch(mutationName: string, ...args: any[]): void;
  6. dispatch<P>(mutation: MutationObject<P>): void;
  7. replaceState(state: S): void;
  8. watch<T>(getter: Getter<S, T>, cb: (value: T) => void, options?: WatchOption): void;
  9. hotUpdate(options: {
  10. mutations?: MutationTree<S>;
  11. modules?: ModuleTree;
  12. }): void;
  13. subscribe(cb: (mutation: MutationObject<any>, state: S) => void): () => void;
  14. }
  15. export function install(Vue: vuejs.VueStatic): void;
  16. export interface StoreOption<S> {
  17. state?: S;
  18. mutations?: MutationTree<S>;
  19. modules?: ModuleTree;
  20. plugins?: Plugin<S>[];
  21. strict?: boolean;
  22. }
  23. type Getter<S, T> = (state: S) => T;
  24. type Action<S> = (store: Store<S>, ...args: any[]) => any;
  25. type Mutation<S> = (state: S, ...args: any[]) => void;
  26. type Plugin<S> = (store: Store<S>) => void;
  27. export interface MutationTree<S> {
  28. [key: string]: Mutation<S>;
  29. }
  30. export interface MutationObject<P> {
  31. type: string;
  32. silent?: boolean;
  33. payload?: P;
  34. }
  35. export interface Module<S> {
  36. state?: S;
  37. mutations?: MutationTree<S>;
  38. modules?: ModuleTree;
  39. }
  40. export interface ModuleTree {
  41. [key: string]: Module<any>;
  42. }
  43. export interface VuexComponentOption<S> {
  44. getters: { [key: string]: Getter<S, any> };
  45. actions: { [key: string]: Action<S> };
  46. }
  47. export interface WatchOption {
  48. deep?: boolean;
  49. immidiate?: boolean;
  50. }