Replies: 3 comments 2 replies
-
Ok so after reading through the docs again, the first two listed below seem like they could work - haven't had a chance to try yet though so unsure of tradeoffs. The third, overrides, is interesting at first glance but seems to be for a different use case - could be wrong though.
|
Beta Was this translation helpful? Give feedback.
-
@marbemac yes, well found. I was going to suggest bullet 2 (instances as params). We do that in multiple places to accomplish basically exactly what you're describing - instead of passing a function around, pass a whole atom instance that wraps the function. Depending on your setup, creating that atom instance using bullet 1 (an atom factory) could be ideal. Bullet 3 is how you would typically manage this in a DI system, however overrides in Zedux apply to the whole ecosystem, you can't override an atom differently in two places in the same ecosystem. I have some thoughts of future features to maybe allow for that, but I can't really say it'll ever happen at this point. |
Beta Was this translation helpful? Give feedback.
-
Ah one more q - is there anything similar to the |
Beta Was this translation helpful? Give feedback.
-
For example, take this
data-table
atom - it calls a "fetchRowIds" function here -> https://github.com/marbemac/zedux-grid-example/blob/main/app/components/DataTable/atoms.ts#L56.This
fetchRowIds
function is hardcoded - ideally I'd like this atom to accept afetchRowIds
argument, so that the parent rendering theDataTable
component can pass in it's own implementation offetchRowIds
, which theDataTable
then passes along to the data table atom.Is the recommended approach to add an argument to the function exported by the atom's api? (in this case, to the exported
populateRowIds
function). Downside is that this won't work if the dependency is needed in the atom body (in use effect, etc), and it could be tedious to make sure to pass these injected functions through in all the places that usepopulateRowIds
.Or, is there any way to provide/inject the dependency on a per atom instance basis, when grabbing the atom (via use/injectAtomInstance, etc)? Kind of like params, but without affecting the cache / instance key.
Beta Was this translation helpful? Give feedback.
All reactions