A library that allows you to implement an event/plugin based architecture in dart.

Contains the core logic used in the flocse package

Features

  • Testable and easy to integrate.
  • Easy to learn

Getting started

Create a ComponentRegistry and register any class that extends Component.

As soon as the component is deleted

Usage

class CounterComponent extends Component {
  late int counter;

  @override
  void initListeners() {
    // called before onLoad, use this to register the events
    registerEvent(onIncrement);
    registerEvent(onDecrement);
  }

  Future<void> onIncrement(IncrementEvent e) async {
    // can be fully asynchronous
    await Future.delayed(Duration(milliseconds: Random().nextInt(2000)));
    counter = counter + e.value;
    send(CounterUpdateEvent(counter));
  }

  void onDecrement(DecrementEvent e) {
    // or sync, but will only be called if this exact event is sent
    counter = counter - e.value;
    send(CounterUpdateEvent(counter));
  }

  @override
  void onLoad() {
    // called after register listeners, use this set up your component
    counter = 0;
  }

  @override
  void onUnload() {
      // called right after the listeners are unregistered
  }
}

Additional information

More information soon to come

Libraries

flocse_core
Support for doing something awesome.