arqex / freezer

A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k stars 56 forks source link

Pivot on whole freezer object? #95

Closed solugebefola closed 1 year ago

solugebefola commented 7 years ago

Maybe I am mistaken, but when I try to pivot on an entire freezer object, I don't get back the object, but rather the changed node.

free = new Freezer({a: {b:1, c:2}, d: ["hah", "ho", "hee"], e: [{ze: "zo", zd: "zing"}]});

first = free.get()
//{ a: { b: 1, c: 2 }, d: [ 'hah', 'ho', 'hee' ], e: [ { ze: 'zo', zd: 'zing' } ] }

first.pivot() //Works fine, gives back original
//{ a: { b: 1, c: 2 }, d: [ 'hah', 'ho', 'hee' ], e: [ { ze: 'zo', zd: 'zing' } ] }

second = first.pivot().a.set({b:95})
//Gives back changed node { b: 95, c: 2 }

Am I using it incorrectly?

arqex commented 7 years ago

Hi @solugebefola

it seems that you found some kind of bug when pivot on the root. I need to have a look at the code and check what's happening, but if you need the root object is always a good idea to write freezer.get(), a bit more verbose but you are always sure that you are working with the synced data.

solugebefola commented 7 years ago

Ordinarily I would, but I am not using Freezer in the typical fashion, I don't think. I am including it in a standard react component and using a freezer object (e.g. 'first' in the above) derived from the Freezer ('free') as an attribute in the state. Then i am using standard setState on the freezer object rather than using the Freezer. So I was trying to modify only a portion of the freezer object and return the whole thing as the argument for setState. If this were a project starting from scratch, I would probably use free.get() with a listener rather than setState, but the situation doesn't allow it without a lot of modification to the underlying code. Thanks for letting me know I wasn't crazy!

arqex commented 7 years ago

Hey @solugebefola,

Sorry for my late late reply. I have tested it and for me it's working fine

http://jsbin.com/mizumamota/1/edit?js,console

I don't know if some update has fixed it.