Skip to content

@modoki/engine / index / PlayerPrefs

Variable: PlayerPrefs

const PlayerPrefs: object

Type Declaration

Storage

clear

clear: () => void

Remove every key in this namespace.

Returns

void

delete

readonly delete: (key) => void = del

Parameters
key

string

Returns

void

flush

flush: () => Promise<void>

Resolve once all pending writes are durable. Cancels the debounce and drains immediately; loops so keys dirtied mid-drain are also flushed.

Returns

Promise<void>

get

get: <T>(key) => T | undefined

Read a value. Returns a fresh copy (parsed from cache) — mutating it never affects the store. undefined if the key is absent. Synchronous.

Type Parameters
T

T extends JsonValue = JsonValue

Parameters
key

string

Returns

T | undefined

has

has: (key) => boolean

Parameters
key

string

Returns

boolean

init

init: (opts) => Promise<void>

Hydrate the in-memory cache from the backend. Call once at boot (safe to re-call on a game/namespace swap — it re-hydrates for the new namespace).

Parameters
opts?

PlayerPrefsInitOptions = {}

Returns

Promise<void>

isHydrated

isHydrated: () => boolean

True once init() has hydrated the cache.

Returns

boolean

keys

keys: () => string[]

The logical keys currently stored (this namespace only).

Returns

string[]

set

set: <T>(key, value) => void

Write a value (atomic per key). undefined deletes the key. Synchronous into the cache; the durable write is debounced (see flush()).

Type Parameters
T

T extends JsonValue

Parameters
key

string

value

T | undefined

Returns

void

Built with Modoki.