Make node id serialization optional (#76)

This commit is contained in:
Chenlei Hu
2024-08-17 23:03:11 -04:00
committed by GitHub
parent effa21653a
commit 1cbb74b1b6
2 changed files with 7 additions and 3 deletions

View File

@@ -584,7 +584,7 @@ export declare class LGraph {
/** Destroys a link */ /** Destroys a link */
removeLink(link_id: number): void; removeLink(link_id: number): void;
/** Creates a Object containing all the info about this graph, it can be serialized */ /** Creates a Object containing all the info about this graph, it can be serialized */
serialize<T extends serializedLGraph>(): T; serialize<T extends serializedLGraph>(option?: { sortNodes: boolean }): T;
/** /**
* Configure a graph from a JSON string * Configure a graph from a JSON string
* @param data configure a graph from a JSON string * @param data configure a graph from a JSON string

View File

@@ -2042,9 +2042,13 @@ const globalExport = {};
* @method serialize * @method serialize
* @return {Object} value of the node * @return {Object} value of the node
*/ */
serialize() { serialize(option = { sortNodes: false }) {
var nodes_info = []; var nodes_info = [];
nodes_info = [...this._nodes].sort((a, b) => a.id - b.id).map(node => node.serialize()); nodes_info = (
option?.sortNodes ?
[...this._nodes].sort((a, b) => a.id - b.id) :
this._nodes
).map(node => node.serialize());
//pack link info into a non-verbose format //pack link info into a non-verbose format
var links = []; var links = [];