Encapsule-Annex/jsgraph

Release latest jsgraph w/fix to DirectedGraph.toJSON

Closed this issue · 2 comments

There's a more recent version of jsgraph that's integrated in the Encapsule/ARCcore package (https://github.com/Encapsule/ARCcore). The latest includes a bug fix to DirectedGraph.toJSON which you'll note returns a string, not an object as it should.

If you need this, drop me a note and I'll get the patch applied here.

paste from another comment I made elsewhere that explains this issue and the upcoming fix:

I am using jsgraph in several private projects and you should be aware of upcoming bug fix to DirectedGraph container serialization API methods. Hopefully you haven't encountered the issue yet but it's confusing enough to merit a quick explanation.

Currently, method DirectedGraph.toJSON incorrectly accepts input parameters, and returns a JSON-encoded string. As well, there's another method, DirectedGraph.toObject that returns a serializable JavaScript object.

This is wrong. DirectedGraph.toJSON should return a serializable JavaScript object in the expected format. It should not return a JSON-encoded string. In other words, it should behave exactly like DirectedGraph.toObject does currently.

For example if you create an array of references to DirectedGraph containers and call JSON.stringify on the array we would expect to get a JSON document with an array root element containing N JSON objects each of which is a serialized DirectedGraph instance. But instead we get an array root element containing N strings that are the escaped JSON-encoded result of the current toJSON >:/ that sucks...

In Encapsule/jsgraph vNext:

  • Method DirectedGraph.toJSON has been renamed DirectedGraph.stringify
  • Method DirectedGraph.toObject has been renamed DirectedGraph.toJSON and accepts no in-params.
  • Method DirectedGraph.toObject is aliased to DirectedGraph.toJSON, is deprecated, and will be removed in vNext+?

Note that these fixes are available in the Encapsule/arccore package which you can use as a bridge if you block before I port the source and test updates back to Encapsule/jsgraph.

$ node
> var arccore = require('./index')
undefined
> var jsgraph = arccore.graph
undefined
> var response = jsgraph.directed.create()
undefined
> var digraph = response.result
undefined
> digraph.toJSON()
{ name: '', description: '', vlist: [], elist: [] }
> digraph.toObject()
{ name: '', description: '', vlist: [], elist: [] }
> digraph.stringify(undefined, 4)
'{\n    "name": "",\n    "description": "",\n    "vlist": [],\n    "elist": []\n}'
> digraph.stringify()
'{"name":"","description":"","vlist":[],"elist":[]}'
>