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

How to duplicate one array element ? #75

Closed PlanetIrata closed 8 years ago

PlanetIrata commented 8 years ago

Hi arqex, nice job with your Freezer lib ! I have a little problem, to duplicate the 3rd element of an array, I've tried myarray.splice(2,0,myarray[2]) but after that it seems that the 2 nodes (original and duplicated) point to the same element in memory: changes applied to one of the 2 nodes are reflected in the other. How to deeply duplicate a node array in order to have 2 distinct nodes ?

Thanks for your help.

PlanetIrata commented 8 years ago

ok got it ! have to use toJS() so the correct code to duplicate element 3 (for instance) of an array is myarray.splice(2,0,myarray[2].toJS())

arqex commented 8 years ago

Nice that you could figure it out by yourself :)