Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyus committed Mar 8, 2024
1 parent 3c65035 commit 11de821
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1184,31 +1184,6 @@ class CountController extends BeaconController {
}
```

### BeaconControllerMixin

A mixin for `StatefulWidget`'s `State` class that automatically disposes all beacons and effects created within it.

```dart
class MyController extends StatefulWidget {
const MyController({super.key});
@override
State<MyController> createState() => _MyControllerState();
}
class _MyControllerState extends State<MyController>
with BeaconControllerMixin {
// NO need to dispose these manually
late final count = B.writable(0);
late final doubledCount = B.derived(() => count.value * 2);
@override
Widget build(BuildContext context) {
return Container();
}
}
```

## Dependency Injection

Dependency injection refers to the process of providing an instance of a beacon or BeaconController to your widgets. `state_beacon` ships with a lightweight dependency injection library called [lite_ref](https://pub.dev/packages/lite_ref) that makes it easy and ergonomic to provide Beacons and BeaconControllers to your widgets. It also manages disposal of both.
Expand Down Expand Up @@ -1279,6 +1254,31 @@ class CounterText extends StatelessWidget {
> [!NOTE]
> Even though this is possible, it is recommended to use `BeaconController`s whenever possible. In cases where you only need a single beacon, this can be a convenient way to provide it to a widget.
### BeaconControllerMixin

A mixin for `StatefulWidget`'s `State` class that automatically disposes all beacons and effects created within it.

```dart
class MyController extends StatefulWidget {
const MyController({super.key});
@override
State<MyController> createState() => _MyControllerState();
}
class _MyControllerState extends State<MyController>
with BeaconControllerMixin {
// NO need to dispose these manually
late final count = B.writable(0);
late final doubledCount = B.derived(() => count.value * 2);
@override
Widget build(BuildContext context) {
return Container();
}
}
```

## Pitfalls

When using `Beacon.future`, only beacons accessed before the async gap(`await`) will be tracked as dependencies.
Expand Down

0 comments on commit 11de821

Please sign in to comment.