Arrays in original target are mutated by library
See original GitHub issueWhen you have this code
const item = { numbers: [1, 2] }
ObservableSlim.create(item)
calling Object.keys(item.numbers)
yields ['0', '1', '__length']
instead of just ['0', '1']
.
This is due to the following change: https://github.com/ElliotNB/observable-slim/commit/c69aafd14ca851b63ac76262d951b9d057fa2929#diff-a882dd68fa93398bef8261d2308d9600efd956dbe6ba6ef1f0fe368aa107225dR64
Expected: Original object should not be mutated.
Of course Object.keys()
is not really useful on arrays, but it causes a strange error in jest saying serializes to the same string
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to avoid mutations of objects while pushing them in an ...
At first it works when you generate the first book, but for some weird reason, when you do it a second time you...
Read more >Object Mutation In JavaScript - Dev Genius
All primitives are immutable; that is, they cannot be altered. The variable may be reassigned to a new value, but the existing value...
Read more >Washing your code: avoid mutation - Artem Sapegin
Mutations happen when we change a JavaScript object or array without creating a new variable or reassigning an existing one.
Read more >Immutable Array Methods: Write Cleaner JavaScript Code
Arrays in JavaScript are just objects, which means they can be mutated. In fact, many of the built-in array methods will mutate the...
Read more >Updating Arrays in State - React Docs
To do that, you can create a new array from the original array in your state by calling its non-mutating methods like filter()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I need to test this on my side—it may be an improvement for me. There are differences between the native proxy and the polyfill proxy when it comes to
__length
and in my client code I have to manually filter it out to support IE11 / polyfill. This might remove the need for my manual check.I can see no downsides for my use-cases!
@MZanggl Excellent! I’ll get a PR opened up for it and get it published out on npm soon.