In Javascript, strings are immutable, and making references to strings is equivalent to copying the string istelf.
In Falcor, I can make references to strings using {$type:"ref", value:[...]}
. Falcor claims to maintain data consistency, so that if the model contains references, they end up pointing to the same JS object (so maintaining consistency becomes trivial).
From Falcor docs on JSON Graph:
JSON Graph allows a graph to be modeled as JSON without introducing duplicates. Instead of inserting an entity into the same message multiple times, each entity with a unique identifier is inserted into a single, globally unique location in the JSON Graph object.
However, I can't see how this could apply to strings.
Let say, I have a model like this:
{jsonGraph:{
foo: {text: 'aaa'},
bar: {text: {$type: "ref", value: ["foo", "text"]}},
}}
What happens when I update foo.text
? Will bar.text
be updated too? And if yes, how does it work?