LiveVue.Patch (LiveVue v1.2.1)

Copy Markdown View Source

Encodes LiveVue patch operations into the compact wire format used by data-props-diff and data-streams-diff.

The payload is a concatenated sequence of operations. Dynamic text fields are JavaScript-string-length-prefixed, so paths and values can contain delimiters without extra escaping.

Operation codes:

CodeOperation
aadd
dremove
rreplace
uupsert
llimit
nnonce marker, ignored while decoding

Normal operations use:

<op><path_len>:<path><value>

remove omits <value>. The nonce marker uses n<digits> and exists only to force LiveView to send a changed attribute.

Value tags:

TagValue
znil
b0, b1booleans
n<len>:<number>number
s<len>:<string>string
J<len>:<caret-encoded JSON>maps, lists, and complex values

Paths are transported as JSON Pointer strings unchanged.

Summary

Functions

Deserializes a compact patch payload into list-shaped operations.

Encodes a JSON value for safe, compact HTML attribute transport.

Serializes patch maps into a compact binary payload.

Functions

deserialize(payload)

Deserializes a compact patch payload into list-shaped operations.

Returns [] for an empty payload. Decoded operations are shaped as [op, path] for remove and [op, path, value] for all value-bearing operations. Nonce markers are skipped.

encode_object(value)

Encodes a JSON value for safe, compact HTML attribute transport.

The value is encoded with Jason's default JSON escaping, then JSON quote characters are replaced with ^. Literal ~ and ^ characters are escaped as ~~ and ~^, so the transform is reversible by decode_object/1.

serialize(patches)

Serializes patch maps into a compact binary payload.

Expected patch shapes are %{op: op, path: path, value: value}, %{op: "remove", path: path}, and %{op: "test", path: "", value: nonce}. The nonce test operation is encoded as a marker and is not returned by deserialize/1.