-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move batch logic out of system
- Loading branch information
Showing
4 changed files
with
45 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export 'src/batch.dart'; | ||
export 'src/computed.dart'; | ||
export 'src/effect.dart'; | ||
export 'src/effect_scope.dart'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'system.dart'; | ||
|
||
int batchDepth = 0; | ||
|
||
/// Start a new batch of updates. | ||
/// | ||
/// This function increments the batch depth counter, indicating the start of a new batch of updates. | ||
/// Batching updates can help optimize performance by reducing the number of times the system processes changes. | ||
/// | ||
/// {@template alien_signals.batch.example} | ||
/// ```Example | ||
/// final a = signal(0); | ||
/// final b = signal(0); | ||
/// | ||
/// effect(() { | ||
/// print('effect run'); | ||
/// }); | ||
/// | ||
/// startBatch(); | ||
/// a.set(1); | ||
/// b.set(1); | ||
/// endBatch(); | ||
/// ``` | ||
/// {@endtemplate} | ||
void startBatch() { | ||
++batchDepth; | ||
} | ||
|
||
/// End the current batch of updates. | ||
/// | ||
/// This function decrements the batch depth counter. If the batch depth reaches zero, it triggers the processing | ||
/// of any queued effects that were accumulated during the batch. | ||
/// | ||
/// {@macro alien_signals.batch.example} | ||
void endBatch() { | ||
if ((--batchDepth) == 0) { | ||
drainQueuedEffects(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters