|
1 | | -declare namespace Vuex { |
2 | | - class Store<S> { |
3 | | - constructor(options: StoreOption<S>); |
| 1 | +import "./vue"; |
4 | 2 |
|
5 | | - state: S; |
| 3 | +export * from "./helpers"; |
6 | 4 |
|
7 | | - dispatch(mutationName: string, ...args: any[]): void; |
8 | | - dispatch<P>(mutation: MutationObject<P>): void; |
| 5 | +export declare class Store<S> { |
| 6 | + constructor(options: StoreOptions<S>); |
9 | 7 |
|
10 | | - replaceState(state: S): void; |
| 8 | + readonly state: S; |
| 9 | + readonly getters: any; |
11 | 10 |
|
12 | | - watch<T>(getter: Getter<S, T>, cb: (value: T) => void, options?: WatchOption): void; |
| 11 | + replaceState(state: S): void; |
13 | 12 |
|
14 | | - hotUpdate(options: { |
15 | | - mutations?: MutationTree<S>; |
16 | | - modules?: ModuleTree; |
17 | | - }): void; |
| 13 | + dispatch: Dispatch; |
| 14 | + commit: Commit; |
18 | 15 |
|
19 | | - subscribe(cb: (mutation: MutationObject<any>, state: S) => void): () => void; |
20 | | - } |
| 16 | + subscribe<P extends Payload>(fn: (mutation: P, state: S) => any): () => void; |
| 17 | + watch<T>(getter: (state: S) => T, cb: (value: T) => void, options?: WatchOption): void; |
21 | 18 |
|
22 | | - function install(Vue: vuejs.VueStatic): void; |
| 19 | + registerModule<T>(path: string, module: Module<T, S>): void; |
| 20 | + registerModule<T>(path: string[], module: Module<T, S>): void; |
23 | 21 |
|
24 | | - interface StoreOption<S> { |
25 | | - state?: S; |
| 22 | + unregisterModule(path: string): void; |
| 23 | + unregisterModule(path: string[]): void; |
| 24 | + |
| 25 | + hotUpdate(options: { |
| 26 | + actions?: ActionTree<S, S>; |
26 | 27 | mutations?: MutationTree<S>; |
27 | | - modules?: ModuleTree; |
28 | | - plugins?: Plugin<S>[]; |
29 | | - strict?: boolean; |
30 | | - } |
31 | | - |
32 | | - type Getter<S, T> = (state: S) => T; |
33 | | - type Action<S> = (store: Store<S>, ...args: any[]) => any; |
34 | | - type Mutation<S> = (state: S, ...args: any[]) => void; |
35 | | - type Plugin<S> = (store: Store<S>) => void; |
36 | | - |
37 | | - interface MutationTree<S> { |
38 | | - [key: string]: Mutation<S>; |
39 | | - } |
40 | | - |
41 | | - interface MutationObject<P> { |
42 | | - type: string; |
43 | | - silent?: boolean; |
44 | | - payload?: P; |
45 | | - } |
46 | | - |
47 | | - interface Module<S> { |
48 | | - state: S; |
49 | | - mutations: MutationTree<S>; |
50 | | - } |
51 | | - |
52 | | - interface ModuleTree { |
53 | | - [key: string]: Module<any>; |
54 | | - } |
55 | | - |
56 | | - interface ComponentOption<S> { |
57 | | - getters: { [key: string]: Getter<S, any> }; |
58 | | - actions: { [key: string]: Action<S> }; |
59 | | - } |
60 | | - |
61 | | - interface WatchOption { |
62 | | - deep?: boolean; |
63 | | - immidiate?: boolean; |
64 | | - } |
65 | | - |
66 | | - function createLogger<S>(option: LoggerOption<S>): Plugin<S>; |
67 | | - |
68 | | - interface LoggerOption<S> { |
69 | | - collapsed?: boolean; |
70 | | - transformer?: (state: S) => any; |
71 | | - mutationTransformer?: (mutation: MutationObject<any>) => any; |
72 | | - } |
| 28 | + getters?: GetterTree<S, S>; |
| 29 | + modules?: ModuleTree<S>; |
| 30 | + }): void; |
| 31 | +} |
| 32 | + |
| 33 | +export declare function install(Vue: vuejs.VueStatic): void; |
| 34 | + |
| 35 | +export interface Dispatch { |
| 36 | + (type: string, payload?: any): Promise<any[]>; |
| 37 | + <P extends Payload>(payloadWithType: P): Promise<any[]>; |
| 38 | +} |
| 39 | + |
| 40 | +export interface Commit { |
| 41 | + (type: string, payload?: any, options?: CommitOptions): void; |
| 42 | + <P extends Payload>(payloadWithType: P, options?: CommitOptions): void; |
| 43 | +} |
| 44 | + |
| 45 | +export interface ActionInjectee<S, R> { |
| 46 | + dispatch: Dispatch; |
| 47 | + commit: Commit; |
| 48 | + state: S; |
| 49 | + getters: any; |
| 50 | + rootState: R; |
| 51 | +} |
| 52 | + |
| 53 | +export interface Payload { |
| 54 | + type: string; |
73 | 55 | } |
74 | 56 |
|
75 | | -declare namespace vuejs { |
76 | | - interface ComponentOption { |
77 | | - vuex?: Vuex.ComponentOption<any>; |
78 | | - store?: Vuex.Store<any>; |
79 | | - } |
| 57 | +export interface CommitOptions { |
| 58 | + silent?: boolean; |
| 59 | +} |
| 60 | + |
| 61 | +export interface StoreOptions<S> { |
| 62 | + state?: S; |
| 63 | + getters?: GetterTree<S, S>; |
| 64 | + actions?: ActionTree<S, S>; |
| 65 | + mutations?: MutationTree<S>; |
| 66 | + modules?: ModuleTree<S>; |
| 67 | + plugins?: Plugin<S>[]; |
| 68 | + strict?: boolean; |
| 69 | +} |
| 70 | + |
| 71 | +export type Getter<S, R> = (state: S, getters: any, rootState: R) => any; |
| 72 | +export type Action<S, R> = (injectee: ActionInjectee<S, R>, payload: any) => any; |
| 73 | +export type Mutation<S> = (state: S, payload: any) => any; |
| 74 | +export type Plugin<S> = (store: Store<S>) => any; |
| 75 | + |
| 76 | +export interface Module<S, R> { |
| 77 | + state?: S; |
| 78 | + getters?: GetterTree<S, R>; |
| 79 | + actions?: ActionTree<S, R>; |
| 80 | + mutations?: MutationTree<S>; |
| 81 | + modules?: ModuleTree<R>; |
| 82 | +} |
| 83 | + |
| 84 | +export interface GetterTree<S, R> { |
| 85 | + [key: string]: Getter<S, R>; |
| 86 | +} |
| 87 | + |
| 88 | +export interface ActionTree<S, R> { |
| 89 | + [key: string]: Action<S, R>; |
| 90 | +} |
80 | 91 |
|
81 | | - interface Vue { |
82 | | - $store?: Vuex.Store<any>; |
83 | | - } |
| 92 | +export interface MutationTree<S> { |
| 93 | + [key: string]: Mutation<S>; |
84 | 94 | } |
85 | 95 |
|
86 | | -declare module 'vuex' { |
87 | | - export = Vuex |
| 96 | +export interface ModuleTree<R> { |
| 97 | + [key: string]: Module<any, R>; |
88 | 98 | } |
89 | 99 |
|
90 | | -declare module 'vuex/logger' { |
91 | | - export default Vuex.createLogger; |
| 100 | +export interface WatchOption { |
| 101 | + deep?: boolean; |
| 102 | + immediate?: boolean; |
92 | 103 | } |
0 commit comments