Practic BUI (Base UI) - v1.0.0
    Preparing search index...

    Type Alias PersistFormat<T>

    How one persisted value is stored, so stored data outlives the code that wrote it: the version this release writes, and how a stored value of any version up to it becomes the value this release shows. Build it with persistFormat.

    type PersistFormat<T> = {
        decode: (stored: PersistStorable) => T | undefined;
        encode: (value: PersistStorable) => PersistStorable;
        read: (stored: PersistStorable, version: number) => T | undefined;
        version: number;
    }

    Type Parameters

    • T
    Index
    decode: (stored: PersistStorable) => T | undefined

    Reads a value as storage holds it, with its version or without one, the same object for the same stored one, as React's useSyncExternalStore needs; nothing for one read refuses or a newer release wrote.

    encode: (value: PersistStorable) => PersistStorable

    The value as storage holds it: with this release's version.

    read: (stored: PersistStorable, version: number) => T | undefined

    Turns a stored value into this release's value, upgrading one of an earlier version.

    Type Declaration

      • (stored: PersistStorable, version: number): T | undefined
      • Parameters

        • stored: PersistStorable

          The value as stored, without its version.

        • version: number

          Its version, 0 for one stored before it had a format.

        Returns T | undefined

        The value to show, or nothing for one it cannot read, which then reads as the initial value.

    version: number

    The format this release writes, from 1. A value stored before it had a format reads as version 0.