2017-01-06 11:38:51 +00:00
|
|
|
import { action, observable } from 'mobx'
|
|
|
|
|
|
|
|
let store = null
|
|
|
|
|
|
|
|
class Store {
|
|
|
|
@observable lastUpdate = 0
|
|
|
|
@observable light = false
|
|
|
|
|
|
|
|
constructor (isServer, lastUpdate) {
|
|
|
|
this.lastUpdate = lastUpdate
|
|
|
|
}
|
|
|
|
|
|
|
|
@action start = () => {
|
|
|
|
this.timer = setInterval(() => {
|
|
|
|
this.lastUpdate = Date.now()
|
|
|
|
this.light = true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
stop = () => clearInterval(this.timer)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initStore (isServer, lastUpdate = Date.now()) {
|
2017-08-19 16:02:40 +00:00
|
|
|
if (isServer) {
|
2017-01-06 11:38:51 +00:00
|
|
|
return new Store(isServer, lastUpdate)
|
|
|
|
} else {
|
|
|
|
if (store === null) {
|
|
|
|
store = new Store(isServer, lastUpdate)
|
|
|
|
}
|
|
|
|
return store
|
|
|
|
}
|
|
|
|
}
|