[WIP] Refactor to use the new jotai store exposed internal methods (Attempt 11) #81
+249
−108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
In Jotai, reactive state is an atom + a store. To scope a value, we can either clone the atom or replace the store. Replacing the store has its own complexities but could be a viable long-term solution. For now, we will continue with the approach that clones atoms. For this to work, we need to ensure that unscoped derived atoms do not needlessly recompute.
Derived atoms that are not explicitly scoped or inherited can either be unscoped or consumer atoms.
To differentiate between consumer and unscoped atoms, we use the following piece of information.
consumer atoms are atoms that read:
Before a consumer atom has first been read, we cannot yet determine whether it is a consumer atom or not. This is currently an UNSOLVED PROBLEM.
Goal
unscoped atoms should not recompute in separate scopes.
The new code should address #25 and #36.
TODO
figure out how determine a consumer atom on first read. Idea: determine this in flushPending to decide whether to notify listeners. Note: this would not address the atomWithObservable bug as that atom has a side-effect in the read function.
fix tests
fix INF loop with getAtom for nested scope providers.
Open Questions