index.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import "./vue";
  2. export * from "./helpers";
  3. export declare class Store<S> {
  4. constructor(options: StoreOptions<S>);
  5. readonly state: S;
  6. readonly getters: any;
  7. replaceState(state: S): void;
  8. dispatch: Dispatch;
  9. commit: Commit;
  10. subscribe<P extends Payload>(fn: (mutation: P, state: S) => any): () => void;
  11. watch<T>(getter: (state: S) => T, cb: (value: T) => void, options?: WatchOption): void;
  12. registerModule<T>(path: string, module: Module<T, S>): void;
  13. registerModule<T>(path: string[], module: Module<T, S>): void;
  14. unregisterModule(path: string): void;
  15. unregisterModule(path: string[]): void;
  16. hotUpdate(options: {
  17. actions?: ActionTree<S, S>;
  18. mutations?: MutationTree<S>;
  19. getters?: GetterTree<S, S>;
  20. modules?: ModuleTree<S>;
  21. }): void;
  22. }
  23. export declare function install(Vue: vuejs.VueStatic): void;
  24. export interface Dispatch {
  25. (type: string, payload?: any): Promise<any[]>;
  26. <P extends Payload>(payloadWithType: P): Promise<any[]>;
  27. }
  28. export interface Commit {
  29. (type: string, payload?: any, options?: CommitOptions): void;
  30. <P extends Payload>(payloadWithType: P, options?: CommitOptions): void;
  31. }
  32. export interface ActionInjectee<S, R> {
  33. dispatch: Dispatch;
  34. commit: Commit;
  35. state: S;
  36. getters: any;
  37. rootState: R;
  38. }
  39. export interface Payload {
  40. type: string;
  41. }
  42. export interface CommitOptions {
  43. silent?: boolean;
  44. }
  45. export interface StoreOptions<S> {
  46. state?: S;
  47. getters?: GetterTree<S, S>;
  48. actions?: ActionTree<S, S>;
  49. mutations?: MutationTree<S>;
  50. modules?: ModuleTree<S>;
  51. plugins?: Plugin<S>[];
  52. strict?: boolean;
  53. }
  54. export type Getter<S, R> = (state: S, getters: any, rootState: R) => any;
  55. export type Action<S, R> = (injectee: ActionInjectee<S, R>, payload: any) => any;
  56. export type Mutation<S> = (state: S, payload: any) => any;
  57. export type Plugin<S> = (store: Store<S>) => any;
  58. export interface Module<S, R> {
  59. state?: S;
  60. getters?: GetterTree<S, R>;
  61. actions?: ActionTree<S, R>;
  62. mutations?: MutationTree<S>;
  63. modules?: ModuleTree<R>;
  64. }
  65. export interface GetterTree<S, R> {
  66. [key: string]: Getter<S, R>;
  67. }
  68. export interface ActionTree<S, R> {
  69. [key: string]: Action<S, R>;
  70. }
  71. export interface MutationTree<S> {
  72. [key: string]: Mutation<S>;
  73. }
  74. export interface ModuleTree<R> {
  75. [key: string]: Module<any, R>;
  76. }
  77. export interface WatchOption {
  78. deep?: boolean;
  79. immediate?: boolean;
  80. }