the node data type of the deserialized graph
the link data type of the deserialized graph
the operators associated with deserialization
get the link data hydrator
set custom hydration for node data
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)));
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
Generated using TypeDoc
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.