Class
Session
View sourceProvides tab-scoped JSON storage as a world resource.
StoragePlugin installs a fresh Session resource. Values are
written to the browser’s sessionStorage, so they survive reloads in the
same tab but are discarded when that tab or its top-level browsing context
ends. Each value is serialized with JSON.stringify by Session#set
and deserialized with JSON.parse by Session#get; values must be
JSON-serializable and returned objects are new parsed values.
The browser must provide the global sessionStorage object when these
methods run.
Examples
import { Session } from '@wimaengine/storage'
const session = world.getResource(Session)
session.set('screen', { name: 'home' })
const screen = session.get('screen')
session.clear()Constructor
Methods
staticdefault(): Session
View sourceset(k: string, v: any): void
View sourceSerializes v and stores it under k in the current tab’s
sessionStorage.
get<T>(k: string): T
View sourceReads and parses the value stored under k.
Returns undefined when sessionStorage.getItem(k) returns a falsy value.
Otherwise, returns the result of JSON.parse; malformed stored JSON
therefore throws the parser’s error.
clear(): void
View sourceRemoves every key from the current tab’s sessionStorage.
This clears the browser storage area shared by the current top-level
browsing context, not only values written through this Session
instance.
