Replies: 3 comments
-
We've contemplated adding something like a @csantos42, have you thought of any cleaner approaches for your use-cases? |
Beta Was this translation helpful? Give feedback.
-
@drarmstr I kind of have the same issue. Lets imagine I have a app that manages Students and Classes. I can only request classes by ID, Students are an array inside of the classes. But I want to track each student in its own atom. I can create the Class in the effect using setSelf. To create the student i would need to get the class in the student effect, or set a student atom from the class effect. I thinks there are lots of use cases where one would need to create any number of other atom that depend on the one you are creating. |
Beta Was this translation helpful? Give feedback.
-
Current debate is if the ability to initiate a transaction, which allows reading and writing from multiple atoms/selectors, would make sense here. It should satisfy your use-cases and would be better than a |
Beta Was this translation helpful? Give feedback.
-
I'd like to implement a write-through cache for an atom using atom effects. The problem is that the atom depends on another global atom and AtomEffect doesn't provide a
get
method. Full details below:I have an app-global,
productRepoAtom
(defined below), that provides access to a remote API. This atom is initialized via RecoilRoot.I'd like to use
productRepoAtom
for other atoms, like anactiveProduct
atom that fetches and caches the currently active product. Right now, I've impelemented activeProduct as a selectorFamily solely so I can useget
on productRepoAtom.The problem is that I can't figure out how to implement a write-through cache for
activeProduct
. Since activeProduct is a selectorFamily I can't use atom effect but I need a selector family to callget
on the productRepoAtom.Here's what I'd like to write:
Q1: How do I implement a write-through cache for an atom if it depends on another atom? I think there's 3 options:
Store productRepo in a global variable and access it directly instead of with an atom. I don't like this approach because it introduces global state in the app. I don't think I can use React context here either. I can't think of a way to dependency inject the productRepo.
Push the cache down into productRepo. I'd prefer to keep caching high up in the stack and recoil seems particularly well suited to handling a cache with atom effects.
I've missed something in Recoil would be the best option.
Beta Was this translation helpful? Give feedback.
All reactions