rsnext/examples/with-mobx/store.js
2019-08-08 14:09:18 -05:00

32 lines
744 B
JavaScript

import { action, observable } from 'mobx'
import { useStaticRendering } from 'mobx-react'
const isServer = typeof window === 'undefined'
useStaticRendering(isServer)
export class Store {
@observable lastUpdate = 0
@observable light = false
hydrate(serializedStore) {
this.lastUpdate =
serializedStore.lastUpdate != null
? serializedStore.lastUpdate
: Date.now()
this.light = !!serializedStore.light
}
@action start = () => {
this.timer = setInterval(() => {
this.lastUpdate = Date.now()
this.light = true
}, 1000)
}
stop = () => clearInterval(this.timer)
}
export async function fetchInitialStoreState() {
// You can do anything to fetch initial store state
return {}
}