nanoclone icon indicating copy to clipboard operation
nanoclone copied to clipboard

[Bug] nanoclone makes vuex state props move onto the prototype

Open mesqueeb opened this issue 6 years ago • 4 comments

I have a weird bug where if I copy my vuex store with nanoclone (I called it copyObj) it will change all the values of the original store and move the MODULE state props onto the prototype. Not the root state props though... image

First console.log above prints the module state props. The second one doesn't, and upon inspection they are moved to the prototype...

mesqueeb avatar Jun 20 '18 07:06 mesqueeb

Strange thing. I'll check it on weekends (sry for this delay).

Kelin2025 avatar Jun 20 '18 10:06 Kelin2025

Here is the bug on Codepen, reproduced in it's simplest form: https://codepen.io/mesqueeb/pen/XYOoOy?editors=0011

This is one of the reasons I can't use nanoclone in my project. Having the props moved to the prototype is a big problem for me.

Also I'm quite afraid what kind of effect this might have on other dependants like nanomerge.

mesqueeb avatar Jul 02 '18 06:07 mesqueeb

Not sure how I missed this issue, but it's because nanoclone is using Object.create which uses the old object as the prototype.

I got around this on my fork, see: https://github.com/ianwalter/clone

ianwalter avatar Apr 29 '19 14:04 ianwalter

I ended up writing my own clone function: copy-anything

mesqueeb avatar Apr 30 '19 01:04 mesqueeb