Member Junction
    Preparing search index...

    Class JSONFieldBinding<T>

    Binds one JSON text field of one entity instance to a live, typed object view.

    • Object → string. GetValue returns a Proxy over the parsed document. Nested plain objects/arrays are wrapped lazily on read (WeakMap-cached, so o.a === o.a), so every reference obtained from the root — however deep, or kept in a local variable — is tracked. Each mutation re-serializes the root and writes it through the entity's normal Set, so dirty tracking and change events work unchanged. Writes that do not change the canonical JSON do not call Set.
    • String → object. The binding remembers the raw text it last saw. When the field's raw value differs on the next read (Load, LoadFromData, Set, revert, …) the document is re-parsed; proxies handed out earlier are then detached (reads still work; WRITES through them throw, so a stale reference can never silently lose an edit or alter the entity behind its dirty tracking). A change that only re-formats identical JSON keeps the current tree so live references survive a Save() round trip.
    • Safety net. A value assigned into the tree and then mutated through the caller's original reference is invisible to the proxy; Flush (called by BaseEntity before validation and save) re-serializes the tree and writes any difference.

    Only plain objects and arrays are wrapped. Date, Map, class instances etc. are left alone — wrapping them would break their internal slots.

    Type Parameters

    • T = unknown
    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    • Type Parameters

      • T = unknown

      Parameters

      • FieldName: string

        the JSON text field this binding is for (used in error messages)

      • readRaw: () => unknown

        reads the field's raw text from the entity

      • writeRaw: (raw: string) => void

        writes raw text to the entity through its normal Set path

      Returns JSONFieldBinding<T>

    Properties

    FieldName: string

    the JSON text field this binding is for (used in error messages)

    Accessors

    Methods

    • Safety net: pushes the tree's current serialization to the entity if it differs from the last sync point. A no-op for a binding that was never read/assigned, and for a tree whose raw text was replaced from outside (the next read re-parses; there is nothing of ours to push).

      Returns void

    • Returns the live view of the field: a Proxy over the parsed document for objects/arrays, the bare value for a primitive JSON root, and null for a null/empty field.

      Returns T

      Error when the field holds text that is not valid JSON

    • Forgets the parsed tree: the next read re-parses from the entity's raw text and every proxy handed out so far is detached. Used when the record's data is replaced wholesale (Revert, reload, NewRecord) — including the case where the replacement text is identical to the text this tree started from, which the raw-text comparison alone cannot distinguish from "nothing happened" when the tree carries un-flushed edits.

      Returns void

    • Assigns a whole new value. null/undefined clears the field. A plain object/array is adopted as the new tree, so later mutation through the caller's own reference is picked up by Flush. Proxies from other records (or from a detached earlier tree) are deep-copied rather than shared.

      Parameters

      • value: T

      Returns void