-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstore.ts
56 lines (49 loc) · 1.2 KB
/
store.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { action, observable } from 'mobx'
export class Store {
@observable showSelectMenu = false
@observable currentMenu = 2
@observable disableScroll = false
@observable likeArticleList: number[] = []
constructor(
showSelectMenu: boolean,
currentMenu: number,
disableScroll: boolean,
likeArticleList: number[]
) {
this.showSelectMenu = showSelectMenu
this.currentMenu = currentMenu
this.disableScroll = disableScroll
this.likeArticleList = likeArticleList
}
@action showMenu = () => {
this.showSelectMenu = true
this.disableScroll = true
}
@action hideMenu = () => {
this.showSelectMenu = false
this.disableScroll = false
}
@action changeCurrentMenu = (id: number) => {
this.currentMenu = id
}
@action setLikeArticleList = (list: number[]) => {
this.likeArticleList = list
}
}
export function initStore(
isServer: boolean,
showSelectMenu = false,
currentMenu = 2,
disableScroll = false,
likeArticleList = []
) {
let store = null
if (isServer) {
return new Store(showSelectMenu, currentMenu, disableScroll, likeArticleList)
} else {
if (store === null) {
store = new Store(showSelectMenu, currentMenu, disableScroll, likeArticleList)
}
return store
}
}