Repository navigation
Conversation
|
Let's go! |
50dd0d0 to
05e7e22
Compare
I am routinely caught off guard by |
|
This would definitely be a nice addition and eliminate the need of being hyper-defensive when writing effects. |
b07bf13 to
6cc5d01
Compare
…fect body.
This commit introduces `splitEffect`, a new reactivity primitive that explicitly
separates the tracking phase from the execution (side-effect) phase.
In a standard `effect`, all signal reads are automatically tracked as dependencies.
This often forces developers to manually wrap their side-effects in `untracked()`
to avoid accidentally tracking signals, which causes unnecessary re-evaluations
or circular updates.
`splitEffect` solves this by accepting two functions:
1. A **tracking function**, where dependencies are explicitly read and returned.
2. An **execution function**, which receives the values and is guaranteed to run
in an untracked context.
```ts
splitEffect(
() => {
val1: tracked1(),
val2: tracked2(),
},
({val1, val2}) => {
log.push(val1,val2);
// This read should not be tracked as a dependency.
untrackedSignal();
},
);
```
fixes angular#56155
6cc5d01 to
29f32ea
Compare
splitEffect, an effect with an untracked effect body.
|
This draft PR is being closed because it has been stale for 28 days and has seen no activity from you. If you'd like to see this change land, you can re-open this PR. Thank you for being an Angular contributor! |
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This is a mere exploration:
This commit introduces
splitEffect, a new reactivity primitive that explicitlyseparates the tracking phase from the execution (side-effect) phase.
In a standard
effect, all signal reads are automatically tracked as dependencies.This often forces developers to manually wrap their side-effects in
untracked()to avoid accidentally tracking signals, which causes unnecessary re-evaluations
or circular updates.
splitEffectsolves this by accepting two functions:in an untracked context.
fixes #56155
Curious about what the community would think of it.