state_beacon_lint

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

state beacon lint

Overview #
This is the liniting package for state_beacon. It provides a set of lint rules to help you write better code and avoid some of its pitfalls.
Installation #
dart pub add custom_lint state_beacon_lint --dev

# or add these lines to your pubspec.yaml
dev_dependencies:
custom_lint:
state_beacon_lint:
copied to clipboard
Enable the custom_lint plugin in your analysis_options.yaml file by adding the following.
analyzer:
plugins:
- custom_lint
copied to clipboard
NB: Create the file if it doesn't exist.
Pitfalls of state_beacon #
When using Beacon.derivedFuture, only beacons accessed before the async gap(await) will be tracked as dependencies.
final counter = Beacon.writable(0);
final doubledCounter = Beacon.derived(() => counter.value * 2);

final derivedFutureCounter = Beacon.derivedFuture(() async {
// This will be tracked as a dependency because it's accessed before the async gap
final count = counter.value;

await Future.delayed(Duration(seconds: count));

// This will NOT be tracked as a dependency because it's accessed after `await`
final doubled = doubledCounter.value;

return '$count x 2 = $doubled';
});
copied to clipboard
When a derivedFuture depends on multiple future/stream beacons

DONT:

final derivedFutureCounter = Beacon.derivedFuture(() async {
// in this instance lastNameStreamBeacon will not be tracked as a dependency
// because it's accessed after the async gap
final firstName = await firstNameFutureBeacon.toFuture();
final lastName = await lastNameStreamBeacon.toFuture();

return 'Fullname is $firstName $lastName';
});
copied to clipboard

DO:

final derivedFutureCounter = Beacon.derivedFuture(() async {
// acquire the futures before the async gap ie: don't use await
final firstNameFuture = firstNameFutureBeacon.toFuture();
final lastNameFuture = lastNameStreamBeacon.toFuture();

// wait for the futures to complete
final (String firstName, String lastName) = await (firstNameFuture, lastNameFuture).wait;

return 'Fullname is $firstName $lastName';
});
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.