From fd838b8c18a6465a29080620cdaa83c1b66fb7ad Mon Sep 17 00:00:00 2001 From: jinyus Date: Sun, 7 Jan 2024 18:33:53 -0500 Subject: [PATCH 1/3] reorganize and add docs --- state_beacon/lib/src/base_beacon.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/state_beacon/lib/src/base_beacon.dart b/state_beacon/lib/src/base_beacon.dart index 9a0715ce..07587df7 100644 --- a/state_beacon/lib/src/base_beacon.dart +++ b/state_beacon/lib/src/base_beacon.dart @@ -56,11 +56,6 @@ abstract class BaseBeacon implements ValueListenable { T? _previousValue; late final T _initialValue; final _listeners = Listeners(); - - T? get previousValue => _previousValue; - T get initialValue => _initialValue; - int get listenersCount => _listeners.length; - final List _disposeCallbacks = []; var _isDisposed = false; bool get isDisposed => _isDisposed; @@ -72,8 +67,20 @@ abstract class BaseBeacon implements ValueListenable { final Finalizer _finalizer = Finalizer((fn) => fn()); // coverage:ignore-end + /// Returns the previous value without subscribing to the beacon. + T? get previousValue => _previousValue; + + /// Returns the initial value without subscribing to the beacon. + T get initialValue => _initialValue; + + /// Returns true if the beacon has been initialized. + int get listenersCount => _listeners.length; + + /// Returns the current value without subscribing to the beacon. T peek() => _value; + /// Returns the current value and subscribes to changes in the beacon + /// when used within a [Beacon.createEffect] or [Beacon.derived]. @override T get value { if (_isEmpty) { From de6055ada49f1cbb168c5d67225c7151e6aea7cc Mon Sep 17 00:00:00 2001 From: jinyus Date: Sun, 7 Jan 2024 18:34:21 -0500 Subject: [PATCH 2/3] make beacons callable as an alternative to .value --- state_beacon/lib/src/base_beacon.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/state_beacon/lib/src/base_beacon.dart b/state_beacon/lib/src/base_beacon.dart index 07587df7..29578c2d 100644 --- a/state_beacon/lib/src/base_beacon.dart +++ b/state_beacon/lib/src/base_beacon.dart @@ -79,6 +79,9 @@ abstract class BaseBeacon implements ValueListenable { /// Returns the current value without subscribing to the beacon. T peek() => _value; + /// Equivalent to calling [value] getter. + T call() => value; + /// Returns the current value and subscribes to changes in the beacon /// when used within a [Beacon.createEffect] or [Beacon.derived]. @override From 0988b4ee0484df074fd1426084aa0c90f6c3d47e Mon Sep 17 00:00:00 2001 From: jinyus Date: Sun, 7 Jan 2024 18:36:45 -0500 Subject: [PATCH 3/3] update tests --- state_beacon/test/src/beacons/derived_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/state_beacon/test/src/beacons/derived_test.dart b/state_beacon/test/src/beacons/derived_test.dart index fe6bb596..a4f58bf0 100644 --- a/state_beacon/test/src/beacons/derived_test.dart +++ b/state_beacon/test/src/beacons/derived_test.dart @@ -9,7 +9,7 @@ void main() { final _ = Beacon.derived(() { effectCount++; - return beacon.value; + return beacon(); }); expect(effectCount, 1); @@ -25,7 +25,7 @@ void main() { final derived = Beacon.derived(() { effectCount++; - return beacon.peek(); + return beacon.call(); }, manualStart: true); expect(effectCount, 0);