An open API service indexing awesome lists of open source software.

https://github.com/modulovalue/single_base

Platform agnostic bloc and storage interfaces for dart
https://github.com/modulovalue/single_base

Last synced: over 1 year ago
JSON representation

Platform agnostic bloc and storage interfaces for dart

Awesome Lists containing this project

README

          

# single_base

DEPRECATED: please use [single_storage_base](https://github.com/modulovalue/single_storage_base) & [single_bloc_base](https://github.com/modulovalue/single_bloc_base)

Platform agnostic bloc and storage interfaces for dart.

Provides interfaces for:
- Disposable Blocs:
```dart
class ExampleBloc implements BlocBase {
const ExampleBloc();

@override
Future dispose() async {
}
}
```
- Initializable Blocs:
```dart
class ExampleBlocWithInit implements InitializableBlocBase {
const ExampleBlocWithInit();

@override
Future dispose() async {
}

@override
Future init() async {
}
}
```
- Disposable & Initializable Blocs:
```dart
class ExampleBaggedBloc extends BaggedInitializableBlocBase {
ExampleBaggedBloc(Iterable blocs,
Iterable initializableBlocs) {
blocs.forEach(bagBloc);
initializableBlocs.forEach(bagState);
disposeLater(() => print("dispose me later"));
initLater(() => print("init me later"));
}
}
```
- Hook Blocs that give you the ability to schedule objects for disposal in one line during their initialization:
```dart

class ExampleHookBloc extends HookBloc {
final MyOtherBloc otherBloc = MyOtherBloc(onInit: HookBloc.disposeBloc);
}

class MyOtherBloc extends BlocBase {
MyOtherBloc({void Function(BlocBase) onInit}) {
onInit(this);
}
}
```

- Platform agnostic storage base class:
```dart
class MyStorage extends StorageBase {
@override
Future exists(String key) async {
return false;
}

@override
Future get(String key) async {
return "todo";
}

@override
String location(String key) {
return key;
}

@override
Future remove(String key) async {
// remove
}

@override
Future set(String key, String value) async {
// set
}
}

final storage = MyStorage();
final storageAt = storage.at("somewhere");
final storageSomewhereElse = storage.map((key) => "somewhere/$key");
```