eventify 0.1.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new74

EventEmitter #

EventEmitter for dart. This can be used in any application to register for events and get notified once it is fired.


This library provide mechanism to register for event notifications with emitter or publisher and get notified in the event of an event.

One main advantage of the mehanism is that, it support context from where the subscriber is listening. The context could be any additional data the subscriber is interested in.

Another feature this has is the ability to receive sender information, which could be handy if the subscriber wish to know about the publisher.

Example #

    void performAddition(){

    }

    EventCallback cb = (ev, cont) {
        if (null != ev) {
          switch (ev.eventName) {
            case "add":
              performAddition();
              break;
          }
        }
      };

    EventEmitter emitter = new EventEmitter();
    Listener listener = emitter.on("add", this , cb);

    emitter.emit("add","keyboard",10);


As shown in the above example, it is easy to register for events and get notified once it is triggered.

0.1.3 #

  • Performance optimization - Observed that in real-time applications, removing event handlers were taking lots of time. Same observed with adding handlers also.
  • Modified code to use Set, instead of list to provide faster performance.
  • Removed unwanted checks while adding handlers.

0.1.3 #

  • Addressed health and maintenance suggestions.

0.1.2 #

  • Added additional examples.

0.1.1 #

  • Removing event registration in the callback caused exception. Addressed the issue by creating a sublist and triggering callback from there.

0.1.0 #

  • Added example.dart

0.0.9 #

  • Added CHANGELOG.md

0.0.8 #

First reviewed version.

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';

Future parseStores(Object config) {
  return new Future(() {
    print("Inside the future.");
    if (null != config) {
      Map<String, Map<String, dynamic>> storeConfigs =
          config as Map<String, Map<String, dynamic>>;
      storeConfigs.forEach((str, val) {
        print("${str}:${val}");
        val.forEach((store, details) {
          print("${store}:${details}");
        });
      });
    }
  });
}

void main() {
  Map<String, dynamic> data = {
    "stores": {
      "store1": {"generator": 1, "config": {}},
      "store2": {"generator": 2, "config": {}}
    },
    "models": {
      "model1": {"generator": 1, "name": "modelel1", "linkedStore": "store1"}
    }
  };

  Function parseModels = (config) {};

  print(data.runtimeType);
  data.forEach((key, val) {
    switch (key) {
      case "stores":
        parseStores(val).then((res) {
          print("Store is parsed");
        });
        break;
      case "models":
        parseModels(val);
        break;
      default:
    }
  });

  print("After the loop!!");

  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);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  eventify: ^0.1.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:eventify/eventify.dart';
  
Version Uploaded Documentation Archive
0.1.4 Feb 10, 2019 Go to the documentation of eventify 0.1.4 Download eventify 0.1.4 archive
0.1.3 Feb 5, 2019 Go to the documentation of eventify 0.1.3 Download eventify 0.1.3 archive
0.1.2 Feb 1, 2019 Go to the documentation of eventify 0.1.2 Download eventify 0.1.2 archive
0.1.1 Feb 1, 2019 Go to the documentation of eventify 0.1.1 Download eventify 0.1.1 archive
0.1.0 Feb 1, 2019 Go to the documentation of eventify 0.1.0 Download eventify 0.1.0 archive
0.0.8 Feb 1, 2019 Go to the documentation of eventify 0.0.8 Download eventify 0.0.8 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
48
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Feb 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.13+1

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:eventify/eventify.dart.

Health suggestions

Fix lib/src/event_emitter.dart. (-0.50 points)

Analysis of lib/src/event_emitter.dart reported 1 hint:

line 34 col 13: Use isEmpty instead of length

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.0.0