index.d.ts 2.5 KB

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