feat!: replace atom getters with ecosystem function properties #169
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.
@affects atoms, react
Description
Atom getters are an unnecessary extra concept for learning Zedux. We can make the ecosystem's existing
get
andgetNode
methods destructurable function properties that do what atom getters currently do.Remove the
ecosystem.live
atom getters and the AtomGettersBase type. Deprecate theAtomGetters
type and point it toEcosystem
itself.Add a circular
ecosystem
property to ecosystems that references itself. This is for backwards compatibility with the old atom getters type. To upgrade simply stop destructuring that property off the ecosystem and use the ecosystem directly.Add
getNodeOnce
andgetOnce
destructurable function properties to Ecosystem.Make the Ecosystem
get
,getNode
, andselect
methods destructurable function properties for full compatibility with the old atom getters type.Deprecate
select
,injectAtomSelector
, anduseAtomSelector
. Add overloads toget
,getNode
,injectAtomValue
,injectAtomInstance
,useAtomValue
, anduseAtomInstance
that accept selectors.Deprecate
injectAtomGetters
in favor of a new injector:injectEcosystem
.Breaking Changes
ecosystem.live
is removed.ecosystem.get
andecosystem.getNode
are now reactive - they will register graph edges in reactive contexts. This is the exact opposite of their prior use which was specifically to prevent registering graph edges. Instead, ecosystems now haveecosystem.getOnce
andecosystem.getNodeOnce
for that.The ability offered by
ecosystem.select
of running an atom selector without caching it no longer exists. This is because it was never a good idea - the selector itself wouldn't be cached, but the atom getters it called would still cache all their resolved nodes. This made it very difficult to clean up those transitive deps manually - hard enough that you'd probably just leave that memory leaked.The recommended approach now is to use
ecosystem.getNode
, allowing the selector to be cached, then useselectorInstance.destroy()
to clear it