perform method
The business logic implementation.
Called by execute. Throw freely — exceptions are caught and converted to BlocxUseCaseFailure automatically.
Return values via success:
return success(myOutput);
Implementation
@override
Future<BlocxUseCaseResult<BlocxPage<T>>> perform(
BlocxSearchInput input,
) async {
recordedInputs.add(input);
if (completer != null) await completer!.future;
if (shouldFail) throw failureError ?? Exception('Search task failed');
final query = input.searchText?.toLowerCase() ?? '';
final matching = source.items.where((item) {
if (matcher != null) return matcher!(item, query);
return item.identifier.toLowerCase().contains(query);
}).toList();
final clampedOffset = input.offset.clamp(0, matching.length);
final endIndex = (clampedOffset + input.limit).clamp(0, matching.length);
final pageItems = matching.sublist(clampedOffset, endIndex);
return success(
BlocxPage<T>(
items: pageItems,
offset: clampedOffset,
limit: input.limit,
hasNext: endIndex < matching.length,
),
);
}