LiveFlow.Serializer (LiveFlow v0.4.0)

Copy Markdown View Source

Serializes and deserializes LiveFlow state to/from JSON.

Converts LiveFlow.State structs (with nested Node, Edge, Handle, Viewport structs) to plain maps suitable for Jason.encode!/1, and back again.

Usage

# Export to JSON string
json = LiveFlow.Serializer.to_json(flow)

# Import from JSON string
{:ok, flow} = LiveFlow.Serializer.from_json(json)

# Export to map (for embedding in larger structures)
map = LiveFlow.Serializer.export(flow)

# Import from map
{:ok, flow} = LiveFlow.Serializer.import(map)

Format

The JSON format uses string keys and string representations of atoms. Transient state (selected, dragging, measured, width, height) is excluded from export. On import, these fields get their default values.

Summary

Functions

Exports a flow state to a JSON-compatible map.

Imports from a JSON string.

Imports a flow state from a JSON-compatible map.

Exports a flow state to a pretty-printed JSON string.

Functions

export(flow)

@spec export(LiveFlow.State.t()) :: map()

Exports a flow state to a JSON-compatible map.

Excludes transient UI state (selection, dragging, measurements).

from_json(json)

@spec from_json(String.t()) :: {:ok, LiveFlow.State.t()} | {:error, String.t()}

Imports from a JSON string.

Returns {:ok, state} or {:error, reason}.

import(data)

@spec import(map()) :: {:ok, LiveFlow.State.t()} | {:error, String.t()}

Imports a flow state from a JSON-compatible map.

Returns {:ok, state} or {:error, reason}.

to_json(flow)

@spec to_json(LiveFlow.State.t()) :: String.t()

Exports a flow state to a pretty-printed JSON string.