Last active
November 24, 2025 00:19
-
-
Save loic-sharma/8a5a23f511226492bfded1772d82cbbe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| final counter = signal(0); | |
| final userProfile = signal({ 'name': 'Guest' }); | |
| final counterSquared = computed((context) { | |
| final count = context.watch(counter); | |
| return count * count; | |
| }) | |
| final printEffect = effect((context) { | |
| final count = context.watch(counter); | |
| print('Counter changed to $count'); | |
| }); | |
| counterSquared.dispose(); | |
| printEffect.dispose(); | |
| final transaction = SignalTransaction()..addAll([counter, userProfile]); | |
| transaction.add(counter); | |
| counter.value = 5; | |
| userProfile.value = { 'name': 'Alice' }; | |
| transaction.commit(); | |
| class Foo extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Text('Count: ${context.watch(counter)}'); | |
| } | |
| } | |
| // https://github.com/brianegan/flutter_architecture_samples/blob/d898d1329e04e5b5fbdef1285b39ef975a6b8efa/signals/lib/todo_list_controller.dart#L4 | |
| class TodoModel { | |
| ListSignal<Todo> todos = signal([]); | |
| ReadonlyListSignal<Todo> get completedTodos => computed((context) { | |
| return context.watch(todos).where((todo) => todo.isCompleted).toList(); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment