feat!: implement untrack
and rework injectors
#170
Merged
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, stores
Description
As per the v2 spec, effects should run immediately after atom evaluation by default. There's no need to wait for a
setTimeout
tick to run them. Users can wrap the callback in asetTimeout
themselves if they really need to wait a tick. But also, they just pretty much never should.Remove the old
createInjector
util. Replace it withinjectPrevDescriptor
andsetNextDescriptor
- two much more lightweight and flexible utils that essentially do the same thing.Remove
readInstance
. Move its logic toinjectSelf
which was previously a direct alias ofreadInstance
. Update all injectors to useinjectSelf
.Remove
injectValidate
.Implement a new
untrack
utility patterned after other signals libs like Solid. Use it ininjectMemo
andinjectEffect
to prevent their callbacks from tracking reactive dependencies for the containing atom instance.Breaking Changes
The previously-deprecated
injectValidate
injector is now removed. Use this instead:The callbacks passed to
injectMemo
andinjectEffect
(withsynchronous: true
) now no longer track reactive dependencies. This is technically a breaking change, though it can be considered a bug that's now fixed.Effects no longer wait a tick to run. This means that when accessing atoms statically, effects are already registered. This is technically a breaking change, but also can be considered a bug with previous behavior.