blix_signals 0.3.2

  • README.md
  • Installing
  • Versions
  • 0

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';
  
Version Uploaded Documentation Archive
0.3.2 Nov 14, 2013 Go to the documentation of blix_signals 0.3.2 Download blix_signals 0.3.2 archive
0.3.1 Oct 27, 2013 Go to the documentation of blix_signals 0.3.1 Download blix_signals 0.3.1 archive
0.3.0 Oct 27, 2013 Go to the documentation of blix_signals 0.3.0 Download blix_signals 0.3.0 archive
0.2.2 Oct 26, 2013 Go to the documentation of blix_signals 0.2.2 Download blix_signals 0.2.2 archive
0.2.1 Oct 26, 2013 Go to the documentation of blix_signals 0.2.1 Download blix_signals 0.2.1 archive
0.2.0 Oct 26, 2013 Go to the documentation of blix_signals 0.2.0 Download blix_signals 0.2.0 archive
0.1.1 Oct 25, 2013 Go to the documentation of blix_signals 0.1.1 Download blix_signals 0.1.1 archive
0.1.0 Oct 25, 2013 Go to the documentation of blix_signals 0.1.0 Download blix_signals 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
1
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: unsure

Error(s) prevent platform classification:

Error(s) in lib/signal.dart: Type parameter bound types must be instantiated.

Issues and suggestions

Fix lib/signal.dart.

Analysis of lib/signal.dart failed with 5 errors, 1 hint, including:

line 157 col 43: Type parameter bound types must be instantiated.

line 165 col 35: Type parameter bound types must be instantiated.

line 200 col 2: Invalid override. The type of '_PendingCall.previous' ('() → _LinkedListEntry<_PendingCall>') isn't a subtype of '_LinkedListEntry<_PendingCall>.previous' ('() → _PendingCall').

line 201 col 2: Invalid override. The type of '_PendingCall.next' ('() → _LinkedListEntry<_PendingCall>') isn't a subtype of '_LinkedListEntry<_PendingCall>.next' ('() → _PendingCall').

line 287 col 2: Invalid override. The type of 'Signal.dispatch' ('(T) → void') isn't a subtype of 'IDispatcher<T>.dispatch' ('(dynamic) → void').

Fix platform conflicts.

Error(s) prevent platform classification:

Error(s) in lib/signal.dart: Type parameter bound types must be instantiated.

Maintain CHANGELOG.md.

Changelog entries help clients to follow the progress in your code.

Package is too old.

The package was released more than two years ago.

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use blix_signals.dart.

Format lib/signals.dart.

Run dartfmt to format lib/signals.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=0.7.6
Dev dependencies
benchmark_harness any
unittest any