Created
December 9, 2021 16:48
-
-
Save Emex4gman/64cf5ae8e925f8491320fe9798ab4eb4 to your computer and use it in GitHub Desktop.
Smaple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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