Registry / http-networking / vue-deepunref

vue-deepunref

JSON →
library1.0.1jsnpmunverified

vue-deepunref is a specialized utility for Vue 3 applications designed to recursively unwrap `Ref` objects within a nested data structure. It serves as a programmatic counterpart to Vue's `toRefs` utility, which converts reactive properties into individual refs. `deepUnref`, in contrast, traverses objects and arrays, applying `unref()` to every encountered ref until the entire structure is composed of plain JavaScript values, free from reactivity. This is particularly useful for scenarios where reactive objects, like form data, need to be passed to external systems that expect plain JavaScript objects, such as a validation library, a REST API endpoint for `POST` requests, or a serialization process. The current stable version is 1.0.1, indicating a stable, single-purpose library without a rapid release cadence. Its primary differentiator is its deep, recursive unwrapping capability, addressing a common pattern in Vue 3 development.

npm install vue-deepunref
INSTALL
IMPORT
SIG · VUE-DEEPUNREF
V
vue-deepunref
http-networkingjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

deepUnref
import { deepUnref } from 'vue-deepunref'
const { deepUnref } = require('vue-deepunref')
The primary and only named export for deeply unwrapping Vue refs. The package is ESM-first and CommonJS `require` is generally not supported for direct module import since v1.
deepUnref
import { deepUnref } from 'vue-deepunref'
import deepUnref from 'vue-deepunref'
deepUnref is a named export, not a default export. Using default import will result in 'deepUnref is not a function' errors.

Demonstrates how to use `deepUnref` to convert a complex reactive object containing nested `ref`s into a plain JavaScript object suitable for API submission or external library consumption, illustrating how the original reactive object remains unaffected.

import { ref } from 'vue'; import { deepUnref } from 'vue-deepunref'; // Assume saveRest is a function that sends data to a backend async function saveRest(data: Record<string, any>) { console.log('Sending data:', JSON.stringify(data, null, 2)); // In a real application, this would be an actual API call return new Promise(resolve => setTimeout(() => resolve({ success: true, data }), 500)); } const formData = { name: ref('Alice Smith'), age: ref(30), address: { street: ref('123 Vue Lane'), city: ref('Refsburg') }, tags: [ref('frontend'), ref('vue-3')], preferences: ref({ notifications: ref(true), theme: 'dark', language: ref('en-US') }), items: [ { id: 1, name: ref('Item A') }, { id: 2, name: ref('Item B'), quantity: ref(5) } ] }; console.log('Original form data (reactive structure):', formData); // Simulate sending form data to a backend that expects plain objects // deepUnref creates a new plain object structure without affecting the original. const result = await saveRest(deepUnref(formData)); console.log('API response:', result); // Verify that the original form data remains reactive console.log('Original form data after unref operation (still reactive):', formData.name.value); formData.name.value = 'Bob Johnson'; console.log('Original form data updated:', formData.name.value);
Debug
Known issues
gotcha`deepUnref` focuses exclusively on unwrapping Vue 3 `Ref` objects. While it recreates the object/array structure, it does not perform a deep clone of nested plain JavaScript objects or arrays. Therefore, any non-ref objects or arrays within the input that are referenced by multiple parts of your application might still be shared by reference in the `deepUnref` output.
fix
If complete independence and deep cloning of all nested structures (not just unwrapping refs) is required, consider using a dedicated deep cloning utility (e.g., `lodash.clonedeep`) on the object *before* or *after* applying `deepUnref`.
affects: >=1.0.0
gotcha`deepUnref` is specifically designed for `Ref` objects created with `ref()` in Vue 3. It will not inherently unwrap or modify `reactive()` objects directly, nor is it compatible with Vue 2's reactivity system. Passing a `reactive` object directly will result in a shallow copy of the proxy, not an unwrapped plain object.
fix
Ensure your input to `deepUnref` primarily contains `Ref` objects. If you need to unwrap a `reactive` object, first convert its properties to individual refs using `toRefs()` or explicitly extract `.value` from its properties before forming the input object.
affects: >=1.0.0
gotchaFor very large or deeply nested objects, `deepUnref` performs a recursive traversal. While generally efficient, be mindful of potential performance implications on extremely complex data structures, especially in performance-critical loops or computations, due to the creation of new objects/arrays.
fix
Profile your application if performance issues arise when using `deepUnref` with extremely large datasets. Consider optimizing the data structure or unwrapping only the necessary parts if full deep unwrapping becomes a bottleneck.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'value')
Attempting to access the `.value` property on a field that has already been unwrapped by `deepUnref`.
fix
After calling `deepUnref`, the resulting object no longer contains `Ref` objects, so direct property access is sufficient (e.g., `unreffedObject.myProp` instead of `unreffedObject.myProp.value`).
Module not found: Can't resolve 'vue-deepunref'
The package is not installed or the import path is incorrect.
fix
Run `npm install vue-deepunref` or `yarn add vue-deepunref`. Verify the import path is `import { deepUnref } from 'vue-deepunref';`.
deepUnref is not a function
Incorrect import method (e.g., `import deepUnref from 'vue-deepunref'`) or a typo in the named import.
fix
Ensure you are using a named import: `import { deepUnref } from 'vue-deepunref';`. This package does not provide a default export.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
vuerequiredRuntime peer dependency for Vue 3 reactivity system, as it operates on Vue Ref objects.
Agent activity
37 hits · last 30 days
node
32
OpenAI (training)
1
Resources
vue-deepunref — npm install vue-deepunref · libregistry