index.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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) => 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): Promise<any[]>;
  29. <P extends Payload>(payloadWithType: P): 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. }
  42. export interface Payload {
  43. type: string;
  44. }
  45. export interface CommitOptions {
  46. silent?: boolean;
  47. }
  48. export interface StoreOptions<S> {
  49. state?: S;
  50. getters?: GetterTree<S, S>;
  51. actions?: ActionTree<S, S>;
  52. mutations?: MutationTree<S>;
  53. modules?: ModuleTree<S>;
  54. plugins?: Plugin<S>[];
  55. strict?: boolean;
  56. }
  57. export type Getter<S, R> = (state: S, getters: any, rootState: R) => any;
  58. export type Action<S, R> = (injectee: ActionContext<S, R>, payload: any) => any;
  59. export type Mutation<S> = (state: S, payload: any) => any;
  60. export type Plugin<S> = (store: Store<S>) => any;
  61. export interface Module<S, R> {
  62. state?: S;
  63. getters?: GetterTree<S, R>;
  64. actions?: ActionTree<S, R>;
  65. mutations?: MutationTree<S>;
  66. modules?: ModuleTree<R>;
  67. }
  68. export interface GetterTree<S, R> {
  69. [key: string]: Getter<S, R>;
  70. }
  71. export interface ActionTree<S, R> {
  72. [key: string]: Action<S, R>;
  73. }
  74. export interface MutationTree<S> {
  75. [key: string]: Mutation<S>;
  76. }
  77. export interface ModuleTree<R> {
  78. [key: string]: Module<any, R>;
  79. }