Skip to content

Instantly share code, notes, and snippets.

@Emex4gman
Created December 9, 2021 16:48
Show Gist options
  • Save Emex4gman/64cf5ae8e925f8491320fe9798ab4eb4 to your computer and use it in GitHub Desktop.
Save Emex4gman/64cf5ae8e925f8491320fe9798ab4eb4 to your computer and use it in GitHub Desktop.
Smaple
import { observable } from 'mobx'
import { persist } from 'mobx-persist'
class DeviceStore {
@persist @observable public deviceId: string = ''
constructor() {
this.resolevDeviceId = this.resolevDeviceId.bind(this)
this.resolevDeviceId()
}
async resolevDeviceId() {
let foundUUID = await this.getFromCache()
if (foundUUID === null) {
// generate new uuid
foundUUID = 'NEWUUID'
await this.saveToCahch(foundUUID)
}
this.deviceId = foundUUID
}
async getFromCache(): Promise<string | null> {
return Promise.resolve('UUID')
}
async saveToCahch(uuid: string) {
Promise.resolve(uuid)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment