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
- Host: GitHub
- URL: https://github.com/modulovalue/single_base
- Owner: modulovalue
- License: other
- Created: 2019-08-16T01:26:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-01T16:50:22.000Z (over 6 years ago)
- Last Synced: 2025-02-24T09:05:58.469Z (over 1 year ago)
- Language: Dart
- Homepage: https://pub.dev/packages/single_base
- Size: 23.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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");
```