Viewing version 0.1.0. Open the latest package page.

zone_local

0.1.0

Zone-scoped values. Can be used an alternative to dependency injection.

This package is discontinued upstream.

Download archive

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

VersionPublishedArchiveSHA-256
0.1.0Cached · Upstream SHA-256 matchedDownloadd2ab5fea…6db82e
0.1.1Cached · Upstream SHA-256 matchedDownloade4f1f380…e4c7e2
0.1.2Cached · Upstream SHA-256 matchedDownload279d9c80…f869e5
0.2.0-nullsafety.0Cached · Upstream SHA-256 matchedDownload6887f39a…8ba4bf
0.2.0-nullsafety.1Cached · Upstream SHA-256 matchedDownloadbe21885a…7c6fb3

Dependencies

meta "^1.1.0"