From 1cbb74b1b6fe9f7c6c373ace817ab6b1e84eee94 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Sat, 17 Aug 2024 23:03:11 -0400 Subject: [PATCH] Make node id serialization optional (#76) --- public/litegraph.d.ts | 2 +- src/litegraph.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/public/litegraph.d.ts b/public/litegraph.d.ts index 7f3c7475..eaa1f819 100644 --- a/public/litegraph.d.ts +++ b/public/litegraph.d.ts @@ -584,7 +584,7 @@ export declare class LGraph { /** Destroys a link */ removeLink(link_id: number): void; /** Creates a Object containing all the info about this graph, it can be serialized */ - serialize(): T; + serialize(option?: { sortNodes: boolean }): T; /** * Configure a graph from a JSON string * @param data configure a graph from a JSON string diff --git a/src/litegraph.js b/src/litegraph.js index 3b7b1904..b623a593 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -2042,9 +2042,13 @@ const globalExport = {}; * @method serialize * @return {Object} value of the node */ - serialize() { + serialize(option = { sortNodes: false }) { 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 var links = [];