Add an official utility to clone ref and reactive
#766
Replies: 3 comments
-
|
Since Vue 3 is modular, this would add any weigth. |
Beta Was this translation helpful? Give feedback.
-
|
I absolutely think either Vue or Pinia needs to provide its own reactive-aware clone utility. There's clearly a need for cloning in order to disable reactivity, and the common advice seems to be to just use JSON stringify/parse, which does not support Dates and breaks typing. A single, official utility would provide a lot of clarity. |
Beta Was this translation helpful? Give feedback.
-
|
I am having the same discussion on vueschool.io about the form pattern: This pattern uses the widely (also from @yyx990803) recommended Creating local "raw" copies would also be helpful for partial data editors where you only want to emit the changes after a explicit save / abort action. My current clone helper is based on lodash.cloneDeep but it would be really nice to have something built in: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've stumbled upon this issue: vuejs/core#8975
The recommandation was to use
toRawto clone arefor areactive.But since
refandreactiveallow to compose reactive objects,toRawstill may not work for them due to how it works: https://stackoverflow.com/a/72633173/16716350There are multiple cloning library, but shouldn't Vue ship their own utility for this ?
Since we already have multiple other utility to handle
refandreactivelike https://vuejs.org/api/reactivity-utilities.htmlIt would be useful to add a
toClone()ortoCloned()utility.I've also created an issue in
vuejs/docsto document this:vuejs/docs#3223
Beta Was this translation helpful? Give feedback.
All reactions