Giter Club home page Giter Club logo

flivver's Introduction

Flivver

style: very good analysis

A clean solution to handling callbacks for custom events as a dart library. Are you tired of maintaining initialisation and dispose api of multiple packages in single method? This package helps you modularise event callbacks, allowing for clean, readable and composable code.

Flivver API promotes:

  • testability
  • composability
  • ability to create custom events
  • type safety

Example

See example/example.dart for a complete example.

  • Register a service
  EventHandler.I.registerEventService<MyEventService>(
    MyEventService(),
  );
  EventHandler.I.registerEventServiceLazy<MyOtherEventService>(
    () => MyOtherEventService(),
  );
  • Unregister a service
  EventHandler.I.unregisterEventService(MyEventService());
  // Or
  EventHandler.I.unregisterEventService<MyEventService>();
  • Unregister all services or reset the singleton
  EventHandler.I.reset()
  // Or
  EventHandler.newInstance();
  • Create Event Service
class DependencyInjectionService implements EventService {
  @override
  void call<Event extends Object>(Event currentEvent) {
    if (currentEvent is StartupEvent) {
      // initialising non-auth dependencies
    } else if (currentEvent is LogInEvent || currentEvent is SignInEvent) {
      // initialising auth dependencies
    } else if (currentEvent is LogOutEvent) {
      // clearing dependencies
    }
  }
}

Events

Flivver only cares about the type, Events can be classes or enums. Events can be anything, every service is associated with a list of events for which it will be called.

Event Service

Event services are classes that implement the EventService. These services are registered with the EventHandler against selected events. It has one call method that will be called for events that the service was registered against.

flivver's People

Contributors

chaitanyabsprip avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.