getNextDatapoint<ChildData extends Data, ParentData extends WithOffline?> method
- ParentData data, {
- bool preloadFullImages = false,
gets all the ChildData
points for the given ParentData
if no ParentData
is given it defaults to root
Implementation
Stream<List<ChildData>>
getNextDatapoint<ChildData extends Data, ParentData extends WithOffline?>(
ParentData data, {
bool preloadFullImages = false,
}) async* {
final requestType = Helper.SimulatedRequestType.GET;
assert((await API().user) != null,
S.current!.wontFetchAnythingSinceNoOneIsLoggedIn);
Future<List<ChildData>> merge(
List<ChildData> cached, List<ChildData> upstream) async {
try {
cached.retainWhere((element) => (element as WithOffline).forceOffline);
var cachedIds = cached.map((element) => element.id).toList();
upstream.retainWhere((element) => !cachedIds.contains(element.id));
upstream.addAll(cached);
return upstream;
} catch (e) {
debugPrint("error merging data: " + e.toString());
return cached;
}
}
yield* _run(
itPrefersCache: _dataPrefersCache(data, type: requestType),
offline: () => local.getNextDatapoint(data),
online: () =>
remote.getNextDatapoint(data, preloadFullImages: preloadFullImages),
onlineSuccessCB: (childDatas) => childDatas.forEach((childData) async {
await local.storeData(
childData,
forId: data?.id ?? await API().rootID,
//TODO: uncomment this as soon as offline can mirror everything well #211
// overrideMode: OverrideMode.abortIfExistent,
);
}),
requestType: requestType,
merge: merge,
);
}