wire 0.1.7 wire: ^0.1.7 copied to clipboard
Wire is a publish-subscribe library, with static layer beneath, where responses associated with "keys" called - signals. Simplest possible API - add, remove and send.
import 'package:wire/wire.dart';
main() {
/// SUBSCRIBER EXAMPLE ======================================
const String
SIGNAL_1 = "SIGNAL_1",
SIGNAL_ONCE = "SIGNAL_1_ONCE",
SIGNAL_2 = "SIGNAL_2";
Wire.add(SIGNAL_1, (data) {
print("> SIGNAL 1 (subscriber 1) -> Hello: " + data);
});
Wire.add(SIGNAL_1, (data) {
print("> SIGNAL 1 (subscriber 2) -> Hello: " + data);
});
Wire.send(SIGNAL_1, "World");
Wire.send(SIGNAL_1, "Dart");
Wire.send(SIGNAL_1, "Vladimir");
Wire.remove(SIGNAL_1);
/// SUBSCRIBER END =========================================
/// ONCE EXAMPLE ===========================================
Wire.add(SIGNAL_ONCE, (data) {
print("> SIGNAL 1 (limit 1) -> Goodbye: " + data);
}, 1);
print("\tNo ends: " + Wire.send(SIGNAL_ONCE, "World").toString());
print("\tNo ends: " + Wire.send(SIGNAL_ONCE, "Dart").toString());
print("\tNo ends: " + Wire.send(SIGNAL_ONCE, "Vladimir").toString());
/// ONCE END ===============================================
Wire.add(SIGNAL_2, (data) {
print("> SIGNAL 2 -> I do: " + data);
});
Wire.add(SIGNAL_2, (data) {
print("> SIGNAL 2 (limit 2) -> I do: " + data);
}, 2);
print("\tNo ends: " + Wire.send(SIGNAL_2, "Code").toString());
print("\tNo ends: " + Wire.send(SIGNAL_2, "Gym").toString());
print("\tNo ends: " + Wire.send(SIGNAL_2, "Eat (sometimes)").toString());
print("\tNo ends: " + Wire.send(SIGNAL_2, "Sleep").toString());
print("\tNo ends: " + Wire.send(SIGNAL_2, "Repeat").toString());
}