eventify 0.1.1 copy "eventify: ^0.1.1" to clipboard
eventify: ^0.1.1 copied to clipboard

outdated

A cancellable event emitter which supports context based event driven programming.

example/example.dart

// Copyright (c) 2019, iMeshAcademy authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:eventify/eventify.dart';
import 'dart:async';

void main() {
  EventEmitter emitter = new EventEmitter();
  emitter.on("test", null, (ev, context) {
    print("${ev.eventName} - ${ev.eventData}");
  });

  emitter.emit("test", null, "Test data");

  int count = 0;

  ExtendedEmitter timer = new ExtendedEmitter();
  timer.on("timer", null, (ev, context) {
    count++;
    print("Received ${ev.eventName} event from emitter!");
    if (count == 10) {
      Timer t = ev.eventData as Timer;
      t.cancel();
    }
  });

  timer.doSomeOperation();
}

class ExtendedEmitter extends EventEmitter {
  void timerCallback(Timer timer) {
    emit("timer", this, timer);
  }

  void doSomeOperation() {
    Timer.periodic(Duration(seconds: 1), timerCallback);
  }
}
43
likes
0
pub points
92%
popularity

Publisher

verified publishereventify.biz

A cancellable event emitter which supports context based event driven programming.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on eventify