Will references be preserved?
Closed this issue · 2 comments
Here is an example object:
card =
content: 'hi'
room =
card: card
post:
card: card
In this object, room.card
and room.post.card
point to the same object. Therefore, if I were to execute room.card.content = "bye"
, then room.post.card.content would also equal "bye"
My question is whether this is still preserved after saving into $localForage, i.e.
$localForage.setItem("room_key", room).then ->
$localForage.getItem("room_key").then (r) ->
r.card.content = "hrmm"
// does r.post.card.content also equal "hrmm"?
console.log r
My hope is that it does. When I tested it, it did seem to work, which is great. But that confused me because I thought that it should be saving it as a JSON string and then parsing it back? If that were true, then it seems like the object reference shouldn't be preserved.
So I just wanted to check whether this is true in general, or whether it is some sort of edge case where it's preserved only because I retrieved it immediately after setting it. Thanks!
Looks like it depends on the database you are using. indexedDB supports it.
http://stackoverflow.com/questions/22546304/what-data-types-does-indexeddb-support
Other drivers clearly use JSON in the localForage as you say:
https://github.com/mozilla/localForage/blob/20503c5d844c8884aa69f2328b03fbb064a0625b/src/utils/serializer.js#L127
A jsfiddle that I hacked from the localforage page:
http://jsfiddle.net/ryfo1jk4/47/