Comparing data
To compare things in Javascript, we’re used to using ===
:
This easily breaks down when comparing objects, for example:
This is because although the values are the same, the identity of the objects is different. This is especially problematic when using immutable data since the identity of a (logical) object changes every time we alter it.
Ixfx has a few helper functions to compare things.
isEqualValueDefault compares objects by value.
isEqualValueDefault
will return false if the order of properties changes; use isEqualValueIgnoreOrder
if this matters.
Change sets
compareData compares two objects, producing a set of changes.
Yields:
If a property is added
More
- compareArrays - compare array items
- changedDataFields - treat objects as having the same shape, only looks at values. Throws an error otherwise.
- compareKeys - compare objects based on properties or keys.