summaryrefslogtreecommitdiff
path: root/lib/jotai.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/jotai.dart')
-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);
+ }
}
}