question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussions about rest operator

See original GitHub issue

from: https://github.com/dai-shi/react-hooks-easy-redux/issues/1#issuecomment-471463238

rest operator

const { someKey, ...rest } = someObject
<div>rest.someValue</div>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:32 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
theKasheycommented, Apr 15, 2019

Technically the current implementation of rest is 99% implementation of spread, but I am not sure it is the best way. Probably a small and specific proxy is better

const spread = {
  ...object1,
  ...object2,
} 
// ->
const spread = proxyObjectSpread(object1, object2);
// ------
cosnt proxyObjectSpread = (...objects) => {
  const assingIndex = (object, x) => Object.keys(object).reduce((acc, key) => {acc[key]=x;return acc;},{});
  // create "shape" objects, with values === used used object id
  const spreadKeyHolder = Object.assign({},...(objects.map(assingIndex));
  return new Proxy(spreadKeyHolder, {
    get(key) {
       return objects[spreadKeyHolder[key]][key]; // redirect read
    }
 })
}

PS: You are 100% right.

1reaction
theKasheycommented, Mar 27, 2019

the current implementation would convert array to the object 🤷‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Rest vs Spread Operator – What's the Difference?
The rest operator ( ... ) instructs the computer to add whatever otherInfo (arguments) supplied by the user into an array.
Read more >
Rest parameters - JavaScript - MDN Web Docs
The rest parameter syntax allows a function to accept an indefinite number of arguments as an array, providing a way to represent variadic ......
Read more >
Rest parameters and spread syntax
Rest parameters are used to create functions that accept any number of arguments. · The spread syntax is used to pass an array...
Read more >
JavaScript Spread and Rest Operators: When to Use Them
The rest operator is used to collect multiple elements and condense them into a single array. Let's dive into how to use them....
Read more >
JavaScript | Rest parameter - GeeksforGeeks
The rest parameter syntax allows us to represent an indefinite number of arguments as an array. With the help of a rest parameter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found