mwg API
    Preparing search index...

    Class StoredValue<T>

    One JSON value under one storage key: the read-with-fallback / write / remove trio that PlayerStats, RunHistory and NewsSeenTracker each hand-rolled, with slightly different falsy-vs-null edges per copy. The one here treats any missing or empty read as absent (the raw ? ... : fallback rule two of the three already followed); corrupt JSON or a forbidden key throws a named error (parseInbound), since silently inventing a value would hide a real bug.

    Public so a game can keep its own progress (a level list, a best score) as structured JSON under one key, with defaultStorage() as the storage. Multi-key shapes (Collection's prefix scan, SaveSystem's slots) do not fit it and keep their own code.

    import { StoredValue, defaultStorage } from '@datamoc/mwg/core';

    const progress = new StoredValue<{ solved: number[] }>(defaultStorage(), 'mygame.progress');
    progress.write({ solved: [...progress.read({ solved: [] }).solved, 3] });

    Type Parameters

    • T
    Index
    • the stored value, or fallback when nothing has been written yet

      Parameters

      • fallback: T

      Returns T