blix_signals 0.3.2

Build Status

Signals for Dart #

Signals are a light-weight, strongly-typed way to implement the observer pattern. They allow you to explicitly define the messages your objects provide, without relying on metadata or documentation.

The Signal object at a basic level is a list of methods to be invoked when the Signal is dispatched.

To get started, first add blix_signals to your pubspec.yaml

 dependencies:
  blix_signals: any

Usage Example:

import 'package:blix_signals/signals.dart';

class MilkEvent {
	num amount;
	num duration;
	MilkEvent(this.amount, this.duration);
}

abstract class IMilkable {
	ISignal<MilkEvent> get milked;
}

class Cow implements IMilkable {
	Signal<MilkEvent> _milked = new Signal<MilkEvent>();

	ISignal<MilkEvent> get milked => _milked;

	void milk() {
		if (_milked.isNotEmpty) {
			_milked.dispatch(new MilkEvent(1, 1));
		}
	}
}

class DeliveryPerson {
	void watchMilkable(IMilkable milkable) {
		milkable.milked.add((MilkEvent e) => fillBottle(e.amount));
	}

	void fillBottle(int amount) {
		print("Added ${amount} milk");
	}
}

void main() {
	var cow = new Cow();
	var deliveryPerson = new DeliveryPerson();
	deliveryPerson.watchMilkable(cow);
	cow.milk(); // added 1 milk
}

Three conventions should be pointed out:

  1. The signal is described in past tense.

  2. The dispatch is surrounded by an isNotEmpty check. This is only important for performance if the message requires work to be done. That is, if the message requires a new object to be created, it is best to optimize for the case if there are no handlers.

  3. The exposed interface is using ISignal instead of Signal. The ISignal interface does not expose the dispatch(T) function. This is because it's generally a bad practice to broadcast a message on behalf of another object.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  blix_signals: ^0.3.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:blix_signals/signal.dart';
import 'package:blix_signals/signals.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=0.7.6

Admin