Skip to content

Commit

Permalink
Make node id serialization optional (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Aug 18, 2024
1 parent effa216 commit 1cbb74b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion public/litegraph.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends serializedLGraph>(): T;
serialize<T extends serializedLGraph>(option?: { sortNodes: boolean }): T;
/**
* Configure a graph from a JSON string
* @param data configure a graph from a JSON string
Expand Down
8 changes: 6 additions & 2 deletions src/litegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 1cbb74b

Please sign in to comment.