Replies: 2 comments 15 replies
-
What you have is looking decent so far! instead of use.effect and use.state, create a future with use.memo, and then use.future with that created future (or just return the future directly instead of an AsyncValue, depending on your needs). That way you don’t need to manually set the state. away from my computer so I can’t give you a proper typed-out example right now, but does that make sense? |
Beta Was this translation helpful? Give feedback.
-
This is a more complicated example. There's a shared buffer which is updated using both a stream and a fetch. A stream could be used to combine them (the codebase currently uses RxDart) and then do less work within Rearch but I'm curious how you would approach making this scenario testable with a Rearch based implementation. IOrderedSet<GlucoseReading> glucoseReadingsBuffer(CapsuleHandle use) {
final (timeFrame, _) = use(timeFrameCapsule);
final (buffer, setBuffer) = use.state(IOrderedSet<GlucoseReading>([]));
final glucoseReadings = use(glucoseReadingsCapsule);
final query = (GlucoseReadingQuery q) => q.inTimeRange(timeFrame.toTimeRange());
use.effect(() {
final sub = glucoseReadings.watchChanges(query).listen((diff) {
final updated = buffer
.addAll(diff.inserted)
.addAll(diff.updated)
.removeWhere((gr) => diff.deleted.contains(gr.id))
.toIOrderedSet();
setBuffer(updated);
});
return sub.cancel;
}, [timeFrame]);
use.effect(() {
glucoseReadings.all(query).then((results) => setBuffer(buffer.addAll(results)));
return () {};
}, [timeFrame]);
return buffer;
} |
Beta Was this translation helpful? Give feedback.
-
Given the following
How could I test that the report is updated when the timeRangeCapsule changes? More specifically, how should you wait in the test for the
api.fetchReport
to complete?Beta Was this translation helpful? Give feedback.
All reactions