Class: Storage

rune.data.Storage(id)

Stores JSON-compatible values in localStorage under the application ID plus ".storage". Reads current data for each operation so separate instances do not overwrite unrelated values using stale snapshots. Values are returned as independent JSON data; modifying a returned object requires another set(). Storage access and serialization errors never escape the public methods. A valid explicit application ID is required at construction.

Constructor

new Storage(id)

Creates application-scoped persistent storage.
Parameters:
Name Type Description
id string Unique application ID, matching Application.id.
Source:
Throws:
If the application ID is missing or invalid.
Type
Error

Members

(readonly, nullable) key :string

The localStorage key used by this handler, or null after disposal.
Type:
  • string
Source:

Methods

clear() → {boolean}

Removes this handler's document only. Does not clear other applications or highscore data and never calls localStorage.clear().
Source:
Returns:
Whether removal succeeded.
Type
boolean

dispose() → {undefined}

Releases this handler without deleting persisted data.
Source:
Returns:
Type
undefined

get(name, defaultValueopt) → {*}

Reads a named value. Returns the default for missing data, invalid names, unavailable storage or corrupt JSON. Stored false, zero and null are retained.
Parameters:
Name Type Attributes Description
name string Nonempty value name.
defaultValue * <optional>
Value returned when the name cannot be read.
Source:
Returns:
The stored value or default.
Type
*

has(name) → {boolean}

Tests whether a named value exists, including stored null values.
Parameters:
Name Type Description
name string Nonempty value name.
Source:
Returns:
Whether the value exists and storage is readable.
Type
boolean

remove(name) → {boolean}

Removes a named value without affecting other entries or highscores. A missing value counts as success if storage can be read.
Parameters:
Name Type Description
name string Nonempty value name.
Source:
Returns:
Whether removal succeeded.
Type
boolean

set(name, value) → {boolean}

Saves a value immediately, preserving other entries in this game's storage. JSON-compatible values are accepted. Undefined, functions, symbols, non-finite numbers and cyclic structures fail without changing the persisted document. Objects with toJSON methods follow normal JSON conversion rules.
Parameters:
Name Type Description
name string Nonempty value name.
value * The value to store.
Source:
Returns:
Whether the value was persisted successfully.
Type
boolean