Comments (8)
I'm assuming this is because of the odd way that JS returns a length of 0 for associative arrays.... but perhaps this is intended behavior?
from react-fast-compare.
Can you show us how you are creating those two sample objects in code? And perchance do you know how lodash's isEqual
treats them?
from react-fast-compare.
Sure thing... here's how I created a
:
from react-fast-compare.
Not sure how lodash treats the same... but I will add in the library and attempt the same if you'd like.
from react-fast-compare.
Yeah, so I did this experiment, and lodash (which is generally considered the "most correct" although definitely not the fastest deep compare) behaves similarly:
In RFC's case, we rely on Array.isArray()
returning true
to allow us to just iterate and compare items by length and index up to length. (See https://github.com/FormidableLabs/react-fast-compare/blob/master/index.js#L18-L24 for full implementation). I'm guessing lodash does something similar, as to accommodate the non-standard use case of manually added properties to an object of type Array would need to be something like:
- First, treat as array -- Iterate
i
up to.length
- Second, if all true, treat as object -- iterate
Object.keys
.
... and that's going to have perf implications that we'd really want to balance with a large user-base need. Perhaps you can chat more about how first-class Arrays are coming up with custom, object-style, fields on them to help frame the discussion better? Thanks!
from react-fast-compare.
Interesting... and also makes sense performance-wise.
For my particular use case, switching from the use of an Array to Object to store individual keyed values solved the problem without any need for major refactoring. This is from an older codebase I'm refactoring, so the use of Arrays in this manner is a side-effect of not-so-clean legacy code.
I think it's still important bring up the issue in case anyone else is experiencing the same issue with code that utilizes Arrays in this manner.
Thank you much for verifying and for the detailed response and explanation!
from react-fast-compare.
Hi, is it possible that the same issue can apply to array of objects that have different property values?
For example:
[
{
filterValue: undefined
}
]
[
{
filterValue: "a"
}
]
I have a case where I am comparing react props and the changes that occur are in a nested array object's property value, it doesn't seem to detect the change, unless I reduce the data to the specific objects.
Could it be a similar issue to the above?
Sorry if I am being unclear.
Update: ok I think I know my issue, its because some props have circular references.
from react-fast-compare.
Closing this, as it appears to be resolved/addressed.
from react-fast-compare.
Related Issues (20)
- Upgrade dependencies
- Add ability to compare functions HOT 9
- module '/node_modules/react-fast-compare/index.js' does not provide an export HOT 1
- Handle anonymous function HOT 2
- Bug: Set compares by reference not value HOT 6
- TypeScript library for react-fast-compare? HOT 9
- Fix exported types so that they work for react-redux HOT 8
- Cannot compare object will null prototype HOT 11
- Getters are not considered HOT 2
- IE 11: Object doesn't support property or method 'isView' HOT 26
- There should be a 'debug' feature to determine which fields are breaking equality.
- Types: documentation, clean up, and testing
- Audit security alerts HOT 2
- Fix benchmark chart img path
- Ignore Arrow Functions HOT 1
- Re-evaluate project's eslint rules HOT 1
- Update benchmark png HOT 2
- CJS + ESM Question/discussion HOT 6
- Infra: Switch to GitHub Actions HOT 2
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 react-fast-compare.