-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
41 lines (33 loc) · 779 Bytes
/
store.js
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
import { action, observable } from 'mobx'
let store = null
class Store {
@observable lastUpdate = 0
@observable light = false
@observable name = ""
constructor (isServer, lastUpdate) {
this.lastUpdate = lastUpdate
}
@action updateName = () => {
this.name = "Hello Bro"
}
@action clearName = () => {
this.name = ""
}
@action start = () => {
this.timer = setInterval(() => {
this.lastUpdate = Date.now()
this.light = true
}, 1000)
}
stop = () => clearInterval(this.timer)
}
export function initializeStore (isServer, lastUpdate = Date.now()) {
if (isServer) {
return new Store(isServer, lastUpdate)
} else {
if (store === null) {
store = new Store(isServer, lastUpdate)
}
return store
}
}