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

bug: nodes of value 0 get affected while updating its empty-array sibling #106

Closed gongruixue closed 7 years ago

gongruixue commented 7 years ago

Run the following code:

let frozen = new Freezer({
    a: 0,
    b: []
});
frozen.get().b.set(0, 0);
console.log(frozen.get())

You got {"a":[0],"b":[0]}. The node 'a' was affected, which wasn't what we expected. I digged into the code and found out that in function 'refresh' , if (child == oldChild) was used to find the child node that should be updated. Unfortunately 0==[] returns true, which has caused property 'a' to be updated together with property 'b'. This could be fixed by using === instead.

gongruixue commented 7 years ago

Sorry that I just found my code is outdated... This has been fixed already.