purdy.js
purdy.js copied to clipboard
Implement serialization/deserialization similar to JSONR
This would allow purdy to re-compute references when transmitting JSON output.
- Useful for minimizing data transmitted to the FrontEnd applications.
- Relationships that are
one-to-manyand/ormany-to-manywould refer to the same object.
As of now, purdy handles circular references many-to-many so it would need to be extended to also handle one-to-many relations.
Docs...
- https://github.com/graniteds/jsonr
- https://dzone.com/articles/json-r-json-extension-deals
Technically purdy handles one-to-many by treating it as circular when it isn't truly.
- What do you think about detecting this
reference
var foo = { test: 'ing' }; var bar = { one: foo, two: foo };
/* before: */ {one: {test: 2}, two: [Circular~ one]}
/* after: */ {one: {test: 2}, two: [Reference~ one]}
Strangely it also doesn't do this consistently when the object is empty
var foo = {}; var bar = { one: foo, two: foo };
{one: {}, two: {}}
A truly circular example would be...
var foo = {}; var bar = { a: 3, foo: foo }; foo.bar = bar;
{ a: 3, foo: { bar: [Circular~] } }
Yeah it really should be a reference and I had noticed this during implementation. However, there wasn't a way to distinguish the two easily so I had left it for a moment. I'll have a look at doing this. Thanks!