nbr 1.0.3 copy "nbr: ^1.0.3" to clipboard
nbr: ^1.0.3 copied to clipboard

Generic implementation of the network-bound-resource algorithm in Dart

Network Bound Resource #

Generic implementation of the network-bound-resource algorithm in Dart.

Usage #

Your repository class should extend [NetworkBoundResource].

// For example ...
class MyRepositoryImpl extends NetworkBoundResource implements IMyRepository {}

Then, you can use the fetch() method which returns a stream of Resource objects. For example

Stream<Resource<MapEntry<String, List<String>>>> fetchPackageDependencies(
    String package,
) async* {
    yield* fetch<MapEntry<String, List<String>>, List<String>>(
        fetchFromAPI: () async => await _fetchDependencies(package),
        loadFromDB: () {
            final versions = _mockDB[package];
            return versions != null ? MapEntry(package, versions) : null;
        },
        storeToDB: (entry) => _persistDependencies(entry.key, entry.value),
        shouldFetch: (entry) => entry == null || !_mockDB.containsKey(package),
        mapDTOToEntity: (versions) => MapEntry(package, versions),
    );
}
2
likes
160
pub points
0%
popularity

Publisher

unverified uploader

Generic implementation of the network-bound-resource algorithm in Dart

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on nbr