Skip to content

Commit

Permalink
rm conditional option for derivedFuture and rm test for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyus committed Jan 27, 2024
1 parent 4f13fcf commit 5997fac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 51 deletions.
14 changes: 4 additions & 10 deletions packages/state_beacon_core/lib/src/creator/beacon_creator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ class _BeaconCreator {
bool manualStart = false,
bool cancelRunning = true,
String? name,
bool supportConditional = true,
}) {
final beacon = DerivedFutureBeacon<T>(
compute,
Expand All @@ -515,20 +514,15 @@ class _BeaconCreator {
);

final dispose = doEffect(
() {
() async {
// beacon is manually triggered if in idle state
if (beacon.status() == DerivedFutureStatus.idle) {
return null;
return;
}

return doEffect(
() async {
await beacon.run();
},
supportConditional: supportConditional,
name: name ?? 'DerivedFutureBeacon<$T>',
);
await beacon.run();
},
name: name ?? 'DerivedFutureBeacon<$T>',
);

beacon.$setInternalEffectUnsubscriber(dispose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ class BeaconGroup extends _BeaconCreator {
bool manualStart = false,
bool cancelRunning = true,
String? name,
bool supportConditional = true,
}) {
final beacon = super.derivedFuture<T>(
compute,
manualStart: manualStart,
cancelRunning: cancelRunning,
name: name,
supportConditional: supportConditional,
);
_beacons.add(beacon);
return beacon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,47 +300,9 @@ void main() {
expect(stats.isError, isTrue);
});

test('should not watch new beacon conditionally', () async {
final num1 = Beacon.writable<int>(10);
final num2 = Beacon.writable<int>(20);

final derivedBeacon = Beacon.derivedFuture(
() async {
if (num2().isEven) return num2();
return num1.value + num2.value;
},
supportConditional: false,
manualStart: true,
);

expect(derivedBeacon(), isA<AsyncIdle>());

derivedBeacon.start();

expect(derivedBeacon.isLoading, true);

await Future<void>.delayed(k10ms);

expect(derivedBeacon.unwrapValue(), 20);

num2.increment();

expect(derivedBeacon.isLoading, true);

await Future<void>.delayed(k10ms);

expect(derivedBeacon.unwrapValue(), 31);

// should not trigger recompute as it wasn't accessed on first run
num1.value = 15;

expect(derivedBeacon.isLoading, false);

expect(derivedBeacon.unwrapValue(), 31);
});

test('should stop watching dependencies when it has no more watchers',
() async {
// BeaconObserver.instance = LoggingObserver();
final num1 = Beacon.writable<int>(10, name: 'num1');
final num2 = Beacon.writable<int>(20, name: 'num2');

Expand Down

0 comments on commit 5997fac

Please sign in to comment.