index.d.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import _Vue, { WatchOptions } from "vue";
  2. // augment typings of Vue.js
  3. import "./vue";
  4. export * from "./helpers";
  5. export declare class Store<S> {
  6. constructor(options: StoreOptions<S>);
  7. readonly state: S;
  8. readonly getters: any;
  9. replaceState(state: S): void;
  10. dispatch: Dispatch;
  11. commit: Commit;
  12. subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any): () => void;
  13. subscribeAction<P extends ActionPayload>(fn: (action: P, state: S) => any): () => void;
  14. watch<T>(getter: (state: S, getters: any) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void;
  15. registerModule<T>(path: string, module: Module<T, S>, options?: ModuleOptions): void;
  16. registerModule<T>(path: string[], module: Module<T, S>, options?: ModuleOptions): 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 MutationPayload extends Payload {
  47. payload: any;
  48. }
  49. export interface ActionPayload extends Payload {
  50. payload: any;
  51. }
  52. export interface DispatchOptions {
  53. root?: boolean;
  54. }
  55. export interface CommitOptions {
  56. silent?: boolean;
  57. root?: boolean;
  58. }
  59. export interface StoreOptions<S> {
  60. state?: S;
  61. getters?: GetterTree<S, S>;
  62. actions?: ActionTree<S, S>;
  63. mutations?: MutationTree<S>;
  64. modules?: ModuleTree<S>;
  65. plugins?: Plugin<S>[];
  66. strict?: boolean;
  67. }
  68. export type ActionHandler<S, R> = (injectee: ActionContext<S, R>, payload: any) => any;
  69. export interface ActionObject<S, R> {
  70. root?: boolean;
  71. handler: ActionHandler<S, R>;
  72. }
  73. export type Getter<S, R> = (state: S, getters: any, rootState: R, rootGetters: any) => any;
  74. export type Action<S, R> = ActionHandler<S, R> | ActionObject<S, R>;
  75. export type Mutation<S> = (state: S, payload: any) => any;
  76. export type Plugin<S> = (store: Store<S>) => any;
  77. export interface Module<S, R> {
  78. namespaced?: boolean;
  79. state?: S | (() => S);
  80. getters?: GetterTree<S, R>;
  81. actions?: ActionTree<S, R>;
  82. mutations?: MutationTree<S>;
  83. modules?: ModuleTree<R>;
  84. }
  85. export interface ModuleOptions {
  86. preserveState?: boolean;
  87. }
  88. export interface GetterTree<S, R> {
  89. [key: string]: Getter<S, R>;
  90. }
  91. export interface ActionTree<S, R> {
  92. [key: string]: Action<S, R>;
  93. }
  94. export interface MutationTree<S> {
  95. [key: string]: Mutation<S>;
  96. }
  97. export interface ModuleTree<R> {
  98. [key: string]: Module<any, R>;
  99. }
  100. declare const _default: {
  101. Store: typeof Store;
  102. install: typeof install;
  103. }
  104. export default _default;