Interface Json<NodeDatum, LinkDatum, Ops>

an operator that hydrates serialized json into a graph

Since type information is inherently lost with serialization, use nodeDatum and linkDatum to define node and link data type, and optionally perform extra deserialization.

Type Parameters

  • NodeDatum

    the node data type of the deserialized graph

  • LinkDatum

    the link data type of the deserialized graph

  • Ops extends JsonOps<NodeDatum, LinkDatum>

    the operators associated with deserialization

Hierarchy

  • Json
  • deserialize parsed json as a graph

    Parameters

    • json: unknown

      the parsed json, usually created from JSON.parse

    Returns MutGraph<NodeDatum, LinkDatum>

    graph - the deserialized graph

Methods

  • set custom hydration for link data

    See nodeDatum for example of what Hydrators should look like.

    Type Parameters

    Parameters

    Returns Json<NodeDatum, NL, U<Ops, "linkDatum", NewLink>>

  • get the link data hydrator

    Returns Ops["linkDatum"]

  • set custom hydration for node data

    Type Parameters

    Parameters

    Returns Json<NN, LinkDatum, U<Ops, "nodeDatum", NewNode>>

    Example

    In the simpliest case, this can be used to cast the data types appropriately (or alternatively you could just cast the Graph itself.

    const grf: Graph<number> = ...
    const builder = graphJson().nodeDatum(data => data as number);
    const deser: MutGraph<number> = builder(JSON.parse(JSON.serialize(grf)));

    Example

    Ideally though, you'll use typescripts warnings to make serialization error proof:

    const grf: Graph<number> = ...
    const builder = graphJson().nodeDatum(data => {
    if (typeof data === "number") {
    return data;
    } else {
    throw new Error("...");
    }
    });
    const deser: MutGraph<number> = builder(JSON.parse(JSON.serialize(grf)));
  • get the node data hydrator

    Returns Ops["nodeDatum"]

Generated using TypeDoc