Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded array cloning in getSendToAccounts selector #6448

Merged
merged 1 commit into from
Apr 12, 2019

Conversation

whymarrh
Copy link
Contributor

The use of Object.entries here to map the accounts into a new array effectively produces a shallow clone of the array without guaranteeing the order of the original array (as object iteration order is implementation-specific and variable). From MDN:[1]

The Object.entries() method returns an array of a given object's own enumerable string-keyed property [key, value] pairs, in the same order as that provided by a for...in loop

And also:

The ordering of the properties is the same as that given by looping over the property values of the object manually.

Both of which suggest that the iteration order is the same as for...in, which is to say that it's not specified.[2] [3]

This PR removes the cloning, keeping the shallow clone created the line before which preserves the order of the items in the array.

The use of `Object.entries` here to map the accounts into a new array effectively
produces a shallow clone of the array without guaranteeing the order of the original
array (as object iteration order is implementation-specific and variable). From MDN [1]:

> The **`Object.entries()`** method returns an array of a given object's own enumerable
> string-keyed property `[key, value]` pairs, in the same order as that provided by a
> `for...in` loop

And also:

> The ordering of the properties is the same as that given by looping over the
> property values of the object manually.

Both of which suggest that the iteration order is the same as `for...in`, which is to
say that it's not specified. [2] [3]

This changeset removes the cloning, keeping the shallow clone created the line before
which preserves the order of the items in the array.

  [1]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
  [2]:https://stackoverflow.com/a/5525820/1267663
  [3]:https://stackoverflow.com/a/30919039/1267663
@whymarrh whymarrh merged commit 3a969b2 into MetaMask:develop Apr 12, 2019
@whymarrh whymarrh deleted the getSendToAccounts branch April 12, 2019 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants