Viewing version 0.1.0. Open the latest package page.
zone_local
0.1.0Zone-scoped values. Can be used an alternative to dependency injection.
This package is discontinued upstream.
Readme
Introduction
- Zone-local values are similar to "ThreadLocal" values in multi-threading languages like Java. In terms of performance, creating a new Zone is much cheaper than creating a thread. See explanation of zones at dartlang.org.
- This packages optimizes ease and performance of:
- Getting a zone-scoped value.
- Setting the default values. You can optionally prevent accidental mutations of default values.
- Forking the current zone.
- A minimalistic alternative to dependency injection.
- Introduces a single, easy-to-understand class.
- No compile-time code generation or other magic.
Example
pubspec.yaml
dependencies:
zone_local: ^0.1.0
main.dart
import 'package:zone_local/zone_local.dart';
void main() {
// Configure a zone-local service.
// The method also prevents later (accidental) modification of the default value.
GreetingService.zoneLocal.freezeDefaultValue(GreetingService("Hello, world!"));
// Use the service
print(GreetingService.zoneLocal.value.greeting);
// --> Hello, world!
// Fork a zone with different value
final forkedZone = GreetingService.zoneLocal.forkZoneWithValue(new GreetingService("Hi, forked zone!"));
forkedZone.run(() {
print(GreetingService.zoneLocal.value.greeting);
// --> Hi forked, zone!
});
}
class GreetingService {
static final ZoneLocal<GreetingService> zoneLocal = ZoneLocal<GreetingService>();
final String greeting;
GreetingService(this.greeting);
}
Changelog
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'zone_local:0.1.0'pubspec.yaml
name: zone_local
version: 0.1.0
description: Zone-scoped values. Can be used an alternative to dependency injection.
author: terrier989 <terrier989@gmail.com>
homepage: https://github.com/terrier989/dart-zone_local
environment:
sdk: '>=2.0.0 <3.0.0'
dependencies:
meta: '^1.1.0'
dev_dependencies:
pedantic: '^1.0.0'
test: '^1.4.0'Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | d2ab5fea…6db82e |
| 0.1.1 | Cached · Upstream SHA-256 matched | Download | e4f1f380…e4c7e2 |
| 0.1.2 | Cached · Upstream SHA-256 matched | Download | 279d9c80…f869e5 |
| 0.2.0-nullsafety.0 | Cached · Upstream SHA-256 matched | Download | 6887f39a…8ba4bf |
| 0.2.0-nullsafety.1 | Cached · Upstream SHA-256 matched | Download | be21885a…7c6fb3 |
Dependencies
meta "^1.1.0"