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.

Should detect whole state spreading

See original GitHub issue

With a given code

const mapState = ({ page, direction, ...state }) => ({
  page,
  direction,
  isLoading: isLoading(state)
})

memoize state should not react to any state change, as it would.

Posible solutions:

  1. Currently, memoize react on key get, but it could react on key read. This will require all objects to be wrapped by something with valueOf/toString. They key will be added to tracking if someone “read” it, or “return” it. Could affect performance. Unstable.

  2. Track such situations and encourage a user to change the code

  • cast function to string, and search for spread operator (unstable)
  • detect then all keys of state used, and inform user of a potential problem. Easy to do, could be enabled by default in dev mode.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
theKasheycommented, Mar 13, 2018

There are 2 polyfills, one is simple - could set a trap on set/get/call. Could be done via object.defineProperty. Second is much more complex, and also patches Object methods, to work with “fake” polyfill.

Unfortunately, I’ve failed to solve this task. (for now, looking other ways)

babel-plugin-transform-object-rest-spread destroys the proxy. It just gets all the props outsite “the state”, and stores in another object, already not controlled by me. I could count or “all” methods as used, or all as not used. But I also could trigger on “enumeration”/spreading.

0reactions
theKasheycommented, Mar 13, 2018

As long there is no way to distinguish object spread and deep-equal - that’s really no way to solve this. Solution made:

  1. proxyequal adds a hook to ownKeys injecting the “enumeration trap” then someone going to enumerate object. Not affecting “normal” objects, and production. In case of access to that object proxyequal will inform about enumeration, and memoize-state provide a link to a function.

Solution tried:

  1. Via ownKeys add the “enum-start” and the “enum-end” guard keys. On access the key during enumeration - return something like {[Symbol.toPrimitive]:....}, deferring key access recording. But, if no one will cast “result” to primitive type - it will not work. And nobody will.
  2. During the spread - record all primitive types, but not objects, as long access into objects are still tracked. This will fail situation like state.values ? state.oneKey : state:anotherKey or deep/shallow-compare.

Followup - let user disable this notification, or enable only for top-level keys.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CDC Confirms Person-to-Person Spread of New Coronavirus ...
Recognizing early on that the 2019-nCoV could potentially spread between people, CDC has been working closely with state and local partners ...
Read more >
PSMA PET-CT Accurately Detects Prostate Cancer Spread - NCI
Under the approval, the tracer can be used in PET imaging for prostate cancer that is suspected of having spread to other parts...
Read more >
FACT SHEET: Biden-Harris Administration's Monkeypox ...
The virus, however, is spreading in the United States and globally, and requires a comprehensive response from federal, state, local, ...
Read more >
Home - Illinois.gov
Getting tested for COVID-19 and quarantining if you're positive is a proven method of slowing the spread. If you think you've been exposed...
Read more >
Transmission of SARS-CoV-2: implications for infection ...
Viable SARS-CoV-2 virus and/or RNA detected by RT-PCR can be found on ... Knowing when an infected person can spread SARS-CoV-2 is just...
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