index.d.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. watch<T>(getter: (state: S) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void;
  14. registerModule<T>(path: string, module: Module<T, S>, options?: ModuleOptions): void;
  15. registerModule<T>(path: string[], module: Module<T, S>, options?: ModuleOptions): void;
  16. unregisterModule(path: string): void;
  17. unregisterModule(path: string[]): void;
  18. hotUpdate(options: {
  19. actions?: ActionTree<S, S>;
  20. mutations?: MutationTree<S>;
  21. getters?: GetterTree<S, S>;
  22. modules?: ModuleTree<S>;
  23. }): void;
  24. }
  25. export declare function install(Vue: typeof _Vue): void;
  26. export interface Dispatch {
  27. (type: string, payload?: any, options?: DispatchOptions): Promise<any>;
  28. <P extends Payload>(payloadWithType: P, options?: DispatchOptions): Promise<any>;
  29. }
  30. export interface Commit {
  31. (type: string, payload?: any, options?: CommitOptions): void;
  32. <P extends Payload>(payloadWithType: P, options?: CommitOptions): void;
  33. }
  34. export interface ActionContext<S, R> {
  35. dispatch: Dispatch;
  36. commit: Commit;
  37. state: S;
  38. getters: any;
  39. rootState: R;
  40. rootGetters: any;
  41. }
  42. export interface Payload {
  43. type: string;
  44. }
  45. export interface MutationPayload extends Payload {
  46. payload: any;
  47. }
  48. export interface DispatchOptions {
  49. root?: boolean;
  50. }
  51. export interface CommitOptions {
  52. silent?: boolean;
  53. root?: boolean;
  54. }
  55. export interface StoreOptions<S> {
  56. state?: S;
  57. getters?: GetterTree<S, S>;
  58. actions?: ActionTree<S, S>;
  59. mutations?: MutationTree<S>;
  60. modules?: ModuleTree<S>;
  61. plugins?: Plugin<S>[];
  62. strict?: boolean;
  63. }
  64. type ActionHandler<S, R> = (injectee: ActionContext<S, R>, payload: any) => any;
  65. interface ActionObject<S, R> {
  66. root?: boolean;
  67. handler: ActionHandler<S, R>;
  68. }
  69. export type Getter<S, R> = (state: S, getters: any, rootState: R, rootGetters: any) => any;
  70. export type Action<S, R> = ActionHandler<S, R> | ActionObject<S, R>;
  71. export type Mutation<S> = (state: S, payload: any) => any;
  72. export type Plugin<S> = (store: Store<S>) => any;
  73. export interface Module<S, R> {
  74. namespaced?: boolean;
  75. state?: S | (() => S);
  76. getters?: GetterTree<S, R>;
  77. actions?: ActionTree<S, R>;
  78. mutations?: MutationTree<S>;
  79. modules?: ModuleTree<R>;
  80. }
  81. export interface ModuleOptions{
  82. preserveState?: boolean
  83. }
  84. export interface GetterTree<S, R> {
  85. [key: string]: Getter<S, R>;
  86. }
  87. export interface ActionTree<S, R> {
  88. [key: string]: Action<S, R>;
  89. }
  90. export interface MutationTree<S> {
  91. [key: string]: Mutation<S>;
  92. }
  93. export interface ModuleTree<R> {
  94. [key: string]: Module<any, R>;
  95. }
  96. declare const _default: {
  97. Store: typeof Store;
  98. install: typeof install;
  99. }
  100. export default _default;