Selector use case: optimize rendering of pure/surjective functions
See original GitHub issueThe issue I often deal with involves “surjective” functions for deriving state (from other state slices). That is to say, several different inputs might output the exact same state. I want to avoid re-rendering in that circumstance. Clearly the computation must occur, but for instance, not every useEffect
dependency change necessarily changes state.
Managing the sequential dependency, where one slice is a computationally complex derivation from another, And requires the end-user to review and further “configure” the computed state, while still having the ability to “backtrack” in order to change the inputs, is something I suspect recoil might help with.
Thank you in advance for clarifying how the library might support this use case.
- E
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
LNCS 2967 - Generic Model Management - Springer Link
model management system, introduce the algebraic operators that are used ... 2.4 using selector ... Mapping map is a surjective function onto m...
Read more >Isabelle
This volume is a self-contained introduction to interactive proof in higher- order logic (HOL), using the proof assistant Isabelle.
Read more >The role of linearity in sharing analysis
Linearity plays a key role in sharing analysis, since it allows us to propagate precise sharing information when dealing with method calls.
Read more >Untitled
Frederick md used auto parts, Tsm new jungler reddit, Harga printer brother 6710, Colors salon ... Descargar skin selector cleo 3, Blackbear 4u...
Read more >Maple 7 Programming Guide
9.2 Programming with Plotting Library Functions . . . . . . 421 ... Maple echoes the result—in this case an exact rational...
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
Even with completely pure functions, we can’t say anything about uniqueness of results.
f(0) -> 'a'
andf(1) -> 'a'
So, #314 should control propagation of updates based on the actual result of selector evaluation. In addition, simple reference equality is not always appropriate; we would want to allow for some user-defined value-equality check.Redundant calculations for equivalent inputs are already limited based on selector caching. The current policy is based on reference equality. Internally we use different policies now, but that should not be necessary with #314
Limiting propagation of updates would be really awesome with a functional atom
map()
in #317. Though, it is still fun and useful without that. We actually have implemented it already in #319. However, we don’t want to merge it yet because it encourages risky usage of mapping during a render function. Without memoizing the map function this would lead to a new selector with every render. We tossed around some ideas, but currently thinking of just adding a simple lint rule to protect against this.I’m going to close this issue now as a duplicate of #314, but please clarify if you see a specific example use-case that wouldn’t be covered by that approach.
@edmundsecho
Impurity, I’d imagine.
I know I would love to avoid calculations based on the input. An alternative that makes this less of an issue would be if #317 is implemented, as each
map
,bind
, etc would be a separate selector and halt processing after getting a known output. However, it would encourage splitting what would normally be an acceptable function into more pieces to avoid further computations.Meaning instead of
myAtom.map(x => (x + 5) * 2)
it may encouragemyAtom.map(x => x + 5).map(x => x * 2)
. I don’t know if the number of selectors becomes an issue with splitting things up like that though, so it’s possible that’s a non-issue.