18a9c7e371
* Update `packages/` * Update examples * Update tests * Update bench * Update top level files * Fix build * trigger
33 lines
799 B
JavaScript
33 lines
799 B
JavaScript
import { action, observable } from 'mobx'
|
|
import { useStaticRendering } from 'mobx-react'
|
|
|
|
const isServer = typeof window === 'undefined'
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
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 {}
|
|
}
|