-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to use Map/Set instead of raw Objects
- Loading branch information
Showing
4 changed files
with
487 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c9238dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to bring to your attention that this code :
Produces this output
Due to
JSON.stringify
having some quirks withMap
...I assume many individuals (myself included) use
JSON.stringify
to serialize to json objects for the purpose of transmitting over the wire.i already found a work around for this using yahoo's
serialize-javascript
lib.. but maybe providing a toJson/fromJson methods for marshalling and unmarshalling would be useful..if this is alright will try to create a PR over the weekend or something
c9238dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this wasn't an intentional change (although there's never really been a promise that the graph is JSON-serializable)
The only thing I worry about adding an official
toJSON()
/fromJSON(string)
is that it's possible for someone who is using this library to add a node that has data attached that is notJSON.stringify
able (e.g. as you've shown aMap
, or aFunction
, etc) and it's not clear what the output should be (fromJSON(graph.toJSON())
would not return the same thing)c9238dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, no need to add functions that work depending on domain context.
Also I suspect by the time someone needs a graphlib and is working with data niche enough that JSON.stringify doesn't work, they can easily write a serialiser for their context.
thanks for this lib otherwise, really saved my skin when I needed to topologically sort some data arranged in a dependency tree