GregoryConrad / rearch-dart

Re-imagined approach to application design and architecture
https://pub.dev/packages/rearch
MIT License
92 stars 4 forks source link

warmupToWidget with CapsuleContainer #175

Closed opsb closed 6 months ago

opsb commented 6 months ago

warmupToWidget is really helpful for setting up widgets but there doesn't appear to be an equivalent when using CapsuleContainer s directly. When writing tests against the CapsuleContainer (instead of a widget test with RearchBootstrapper) it would be helpful if you could wait on capsules to be ready e.g.


AppointmentService appointmentService(CapsuleHandle use) {
  final venuesService = use(venuesService);
  final appointmentService = AppointmentService(venuesService);
}

final container = CapsuleContainer();
await container.read(futureVenuesService);
container.read(appointmentService);

Currently it's possible using

final container = CapsuleContainer();
await container.read(futureVenuesService);
container.onNextUpdate(futureVenuesService, () {
  final appointmentService = container.read(appointmentService);
})

but it would be good to have an official way to do it.

busslina commented 6 months ago

https://github.com/GregoryConrad/rearch-dart/discussions/125

GregoryConrad commented 6 months ago

Currently it's possible using

Ohh, definitely don't use onNextUpdate. Of all the experimental APIs I've exposed, that one is the most dangerous to use. That one is designed exclusively for interop with flutter_rearch because the .listen() method has a few quirks if you try to use it to build a changing UI.

As @busslina pointed out, check out #125. That is the way I'd recommend to handle this.