Comments (3)
Hi @lucianobosco due to a potential vulnerability with unsafely setting the diffed properties on the returned diff object, the diffed object is now created using Object.create(null)
. This means that the returned diffed object has no prototype and so hasOwnProperty
will be undefined.
In your case you could spread the diff object into another object with the default prototype functions available.
const diffs = diff(originalResource.value, resource.value)
const d = { ...diffs }
const payload = {
...(d.hasOwnProperty('name') && { name: resource.value.name }),
...(d.hasOwnProperty('slug') && { slug: resource.value.slug }),
...(d.hasOwnProperty('visible') && { visible: resource.value.visible }),
...(d.hasOwnProperty('postCategory') && { post_category_id: resource.value.postCategory?.id || null }),
...(d.hasOwnProperty('parent') && { parent_id: resource.value.parent?.id || null })
}
from deep-object-diff.
Hi @lucianobosco due to a potential vulnerability with unsafely setting the diffed properties on the returned diff object, the diffed object is now created using
Object.create(null)
. This means that the returned diffed object has no prototype and sohasOwnProperty
will be undefined.In your case you could spread the diff object into another object with the default prototype functions available.
const diffs = diff(originalResource.value, resource.value) const d = { ...diffs } const payload = { ...(d.hasOwnProperty('name') && { name: resource.value.name }), ...(d.hasOwnProperty('slug') && { slug: resource.value.slug }), ...(d.hasOwnProperty('visible') && { visible: resource.value.visible }), ...(d.hasOwnProperty('postCategory') && { post_category_id: resource.value.postCategory?.id || null }), ...(d.hasOwnProperty('parent') && { parent_id: resource.value.parent?.id || null }) }
Thanks a lot! That works
from deep-object-diff.
Note that inner objects doesn't have prototype too, so even if you spread the object you might face the same hasOwnProperty is not a function
error.
const diffs = diff(originalResource.value, resource.value)
const d = { ...diffs }
d.innerObj.hasOwnProperty('myProp') // will throw hasOwnProperty is not a function
A different solution than spreading the diff object could be to use Object.hasOwnProperty.call
directly, like this:
Object.hasOwnProperty.call(diffs, prop)
from deep-object-diff.
Related Issues (20)
- Array order considered as not equal?
- deep-object-merge ? HOT 13
- detailedDiff behavior when deleting items from an array does not match README.md documentation HOT 2
- detailedDiff behavior when the last item in an array is deleted, breaking change between 1.1.0 and 1.1.7 HOT 2
- detailedDiff doesn't return deleted elements HOT 1
- Also return original values for deleted and updated? Feature request. HOT 3
- JSON.stringify will omit deleted keys in the result because they are set to undefined HOT 2
- Arrays are returned as Objects, HOT 2
- Return type for `detailedDiff` HOT 1
- No version specified in mjs and cjs spawns errors in webpack HOT 3
- updatedDiff() not suitable for nested array? HOT 3
- Critical security vulnerability HOT 16
- an option to detect "inserted" and removed items in arrays HOT 2
- Not clear behaviour of non-ordered arrays comparison with addedDiff
- when object removed out of array in detailedDiff: get as removal not as change of every index
- Feature Request: Add `equals` method
- Arrays returned as objects HOT 3
- Allow some degree of configuration HOT 1
- A better way to test for changes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deep-object-diff.