Skip to content

Commit

Permalink
Merge pull request #21 from jinyus:patch-4
Browse files Browse the repository at this point in the history
Patch-4
  • Loading branch information
jinyus authored Jan 7, 2024
2 parents d06ee87 + 0988b4e commit c9bf6ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions state_beacon/lib/src/base_beacon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ abstract class BaseBeacon<T> implements ValueListenable<T> {
T? _previousValue;
late final T _initialValue;
final _listeners = Listeners();

T? get previousValue => _previousValue;
T get initialValue => _initialValue;
int get listenersCount => _listeners.length;

final List<VoidCallback> _disposeCallbacks = [];
var _isDisposed = false;
bool get isDisposed => _isDisposed;
Expand All @@ -72,8 +67,23 @@ abstract class BaseBeacon<T> implements ValueListenable<T> {
final Finalizer<void Function()> _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;

/// 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
T get value {
if (_isEmpty) {
Expand Down
4 changes: 2 additions & 2 deletions state_beacon/test/src/beacons/derived_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() {

final _ = Beacon.derived(() {
effectCount++;
return beacon.value;
return beacon();
});

expect(effectCount, 1);
Expand All @@ -25,7 +25,7 @@ void main() {

final derived = Beacon.derived(() {
effectCount++;
return beacon.peek();
return beacon.call();
}, manualStart: true);

expect(effectCount, 0);
Expand Down

0 comments on commit c9bf6ff

Please sign in to comment.