forked from cwdx/pinia-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
38 lines (35 loc) · 751 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { defineStore } from "pinia";
interface State {
messages: string[];
count: number;
}
export const useMainStore = defineStore("main", {
state: (): State => ({
messages: [],
count: 0,
}),
actions: {
addMessage(value: string) {
this.messages = [value, ...this.messages];
},
addAsyncMessage(value: string) {
return new Promise((res) => {
setTimeout(() => {
this.messages = [value, ...this.messages];
res(true);
}, 100);
});
},
mockError() {
return new Promise((_, rej) => {
setTimeout(() => {
rej(false);
}, 100);
});
},
incrementCounter() {
this.count++;
},
},
});
export default useMainStore;