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.

Use Proxy-based selectors

See original GitHub issue

Based on:


Proxy based solutions were floating around for a while, and actually actively used inside(MobX) and outside of React ecosystem(especially in Vue and Immer). I am opening this discussion to resolve status quo and add some momentum to Redux + Proxies investigations.

Overall proxies are capable to solve 3 objective:

  • selector memoization. Proxies can be provide more efficient memoization(comparing to reselect) in some cases, where just some pieces of state matters, as seen in proxy-memoize or redux-tracked
import memoize from 'proxy-memoize';

// reading only `.a` and `.b`
const fn = memoize(x => ({ sum: x.a + x.b, diff: x.a - x.b }));

fn({ a: 2, b: 1, c: 1 }); // ---> { sum: 3, diff: 1 }
fn({ a: 3, b: 1, c: 1 }); // ---> { sum: 4, diff: 2 }
fn({ a: 3, b: 1, c: 9 }); // ---> { sum: 4, diff: 2 } (returning old value)
//                        ^ "c" does not matter
  • testing. While the use case above is a little synthetic and such memoization is not really needed unless a developer willing not to use any memoization at all, it can be used to check selector quality, and report all selectors which react to the state change while they should not

technically running selector twice in dev mode might solve majority of the problems, like returning new array/object every time, proxy based memoization is capable to detect more complicated situations and provide some guidance around the problem. As seen in why-did-you-update image

  • slice isolation. One named issue of redux is it’s “global” store, and the fact that all listeners would be notified on state update. Knowing which slices were updated, and which selectors are listening for them, might provide an optimisation for selectors. This is actually a very old idea - https://github.com/reduxjs/react-redux/pull/1021 - but still valuable.

What proxies can solve:

  • speed. Proxy based memoization works “more often” and might result a better experience
  • less dev pain. Proxies “just works”. At least, in the test mode, they can point on the problem instantly, not asking to invest some hours in debugging.
  • TBD

What proxies cannot solve:

  • per-component memoization. It’s just absolutely orthogonal problem.
  • TBD

What proxies can break:

  • As long as one has to wrap state with a Proxy - one will use Proxy in all “frontend” code. In the same time at reducers/middleware side it will be just state. (Only once) I had a problem with “equal reference” memoization working differently in useSelector and saga. It’s very edge-case-y, but having state sometimes wrapped, and sometimes not can break stuff.

Actionable items:

  • decide about proxy-memoized selector
  • decide about proxy-based selector pureness / quality checking
  • decide about slice isolation or/and proxy-based tracking/DevTools integration. It’s really possible to know which components reading which slice or/and react to a some piece of information and this knowledge can transform DevTools.

cc @markerikson , @dai-shi

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:51 (41 by maintainers)

github_iconTop GitHub Comments

3reactions
markeriksoncommented, Dec 23, 2020

@nathggns as I said, I’m going to be updating my existing blog post at https://blog.isquaredsoftware.com/2017/12/idiomatic-redux-using-reselect-selectors/ with that additional material over the break, as well as trying to add a couple docs pages based on that post.

2reactions
theKasheycommented, Apr 14, 2022

I reckon sooner or later proxies will make their way to the “read” part, as immer made it’s way to the “write” part. But it does not to be today. Let’s wait for a solution we all can recommend without a second thought.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ProxySelector (Java Platform SE 7 ) - Oracle Help Center
Selects the proxy server to use, if any, when connecting to the network resource referenced by a URL. A proxy selector is a...
Read more >
Proxies in Kubernetes
This page explains proxies used with Kubernetes. ... There are several different proxies you may encounter when using Kubernetes:.
Read more >
RFC 6909: IPv4 Traffic Offload Selector Option for Proxy ...
The use of IPv4 Traffic Selector option in the Proxy Binding Update is for allowing the MAG to request the LMA for the...
Read more >
SRX IKEv1 Traffic Selectors vs Proxy Identity
I have two route-based site-to-site VPN tunnels using ESP. Both endpoints are SRX running same OS. The encrypted traffic is as follows. VPN1: ......
Read more >
Tips & Tricks: Why Use a VPN Proxy ID? - Knowledge Base
Devices that support policy-based VPN use specific security ... there is support traffic selector narrowing when the proxy ID setting is ...
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