summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-01-21 18:31:25 -0500
committerMica White <botahamec@outlook.com>2026-01-21 18:31:25 -0500
commit52175e7774d7205c6b9e717d8acc956c48f83c78 (patch)
tree6e7d88b1240f238692969855f3a752d80f10c32e /lib
parentfece0fe726f4788488acae5b063c0c01b6cdf490 (diff)
Fix observers
Diffstat (limited to 'lib')
-rw-r--r--lib/jotai.dart5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/jotai.dart b/lib/jotai.dart
index 16de4e7..5524e6a 100644
--- a/lib/jotai.dart
+++ b/lib/jotai.dart
@@ -85,6 +85,7 @@ final locationAccuracyObservable = observablePreference(
class Observable<T> {
T _value;
int _nextId = 0;
+
// A map is used instead of a list for fast deletions and to avoid memory
// leaks. Storing IDs in a list would make deletion slow, and setting entries
// in the list to null would cause memory leaks.
@@ -92,7 +93,9 @@ class Observable<T> {
Observable(this._value, {List<void Function(T)>? observers}) {
if (observers != null) {
- _observers.addAll(observers.asMap());
+ for (var observer in observers) {
+ subscribe(observer);
+ }
}
}