jinyus / dart_beacon

A reactive primitive (signals) and state management library for dart and flutter
https://pub.dev/packages/state_beacon
28 stars 2 forks source link

Feat: Add Beacon.asFuture #6

Closed jinyus closed 9 months ago

jinyus commented 9 months ago

Exposes a [FutureBeacon] as a [Future] that can be awaited inside another [FutureBeacon].

var count = Beacon.writable(0);
var firstName = Beacon.derivedFuture(() async => 'Sally ${count.value}');

var lastName = Beacon.derivedFuture(() async => 'Smith ${count.value}');

var fullName = Beacon.derivedFuture(() async {

  // no need for a manual switch expression
  final fname = await Beacon.asFuture(firstName);
  final lname = await Beacon.asFuture(lastName);

  return '$fname $lname';
});