streambox_core 1.4.0 copy "streambox_core: ^1.4.0" to clipboard
streambox_core: ^1.4.0 copied to clipboard

Core for stream-based caching and data strategy architecture.

example/main.dart

/// Example usage of streambox_core
///
/// ```dart
/// // πŸ“‚ data layer
/// // response from backend
/// class ItemResponse {
///   // fromJson...
///   // toJson...
/// }
///
/// @RestApi
/// abstract interface class ExampleApiInterface {
///   factory ExampleApiInterface(Dio dio) = _ExampleApiInterface;
///
///   @GET('items')
///   Future`<ItemResponse>` fetchItems({
///     @Query('page') required int page,
///     @Query('size') required int size,
///   });
/// }
///
/// final class ExampleDataSource
///     extends BaseDataSource`<FetchParams, ItemResponse>` {
///   ExampleDataSource({
///     required ExampleApiInterface api,
///     required super.cacheStrategy,
///   }) : _api = api;
///
///   final ExampleApiInterface _api;
///
///   @override
///   Future`<ItemResponse>` request(FetchParams? params) {
///     return _api.fetchItems(page: params!.page, size: params.size);
///   }
/// }
///
/// final class ExampleCache extends BaseKeyValueCache`<ItemResponse>` {
///   const ExampleCache({required super.store});
///
///   @override
///   String get keyPrefix => 'items';
///
///   @override
///   ItemResponse deserialize(String source) =>
///       ItemResponse.fromJson(decodeAsMap(source));
///
///   @override
///   String serialize(ItemResponse value) => encode(value.toJson());
/// }
///
/// final class ExampleRepoImpl
///     extends SingleSourceRepo`<FetchParams, ItemResponse, ExampleEntity>`
///     implements ExampleRepo {
///   ExampleRepoImpl({required super.dataSource});
///
///   @override
///   ExampleEntity map(FetchParams? params, ItemResponse value) =>
///       ExampleMapper(value).toEntity();
/// }
///
/// // πŸ“‚ domain layer
/// class FetchParams implements RequestParams {
///   FetchParams({required this.page, required this.size});
///
///   final int page;
///   final int size;
///
///   @override
///   String get cacheKey => 'cacheKey: $page-$size';
/// }
///
/// class ExampleEntity {
///   //
/// }
///
/// abstract interface class ExampleRepo
///     implements Repo`<FetchParams, ExampleEntity>` {}
///
/// // πŸ“‚ di module
/// final exampleRepo = ExampleRepoImpl(
///   dataSource: ExampleDataSource(
///     api: ExampleApiInterface(dio),
///     cacheStrategy: CacheThenRefreshStrategy(
///       cache: ExampleCache(store: MemoryStoreAdapter()),
///     ),
///   ),
/// );
/// ```
void main() {}
1
likes
0
points
194
downloads

Publisher

verified publisherkalaganov.dev

Weekly Downloads

Core for stream-based caching and data strategy architecture.

Repository (GitHub)
View/report issues

Topics

#repository #caching #reactive #strategy #core

License

unknown (license)

Dependencies

meta

More

Packages that depend on streambox_core