minibus 0.0.1

Minimal Event Bus


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Minibus

A minimalistic, sychronous event bus for D language. Inspired by nanobus for JavaScript.

Usage

import minibus;

struct Counter {
  public int value;

  void increment(int by = 1) {
    this.value += by;
  }
}

void main(string[] args) {
  auto bus = new Minibus();
  auto counter = Counter(0);

  string sub_id = bus.subscribe("increment", (x) => counter.increment());

  bus.emit("increment");
  // counter.value is now 1

  bus.emit("decrement");
  // nothing is subscribed to this event, so the value remains unchanged

  bus.unsubscribe(sub_id);
  bus.emit("increment");
  // counter is unsubscribed from "increment" event, so the value remains unchanged

  bus.subscribe("increment", (value) => counter.increment(value.get!int()));
  bus.emit("increment", new Variant(10));
  // counter.value is now 11
}
Authors:
  • Paweł Świątkowski
Dependencies:
none
Versions:
0.0.1 2021-Mar-20
~main 2021-Mar-20
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 9 downloads total

Score:
0.3
Short URL:
minibus.dub.pm