Git Product home page Git Product logo

eventhub's Introduction

icon EventHub

This project is inspired by EventBus for Android & Java. you can checkout their repository at this link.

This is a project that implements the Pub/Sub model in a decoupled architecture. It can be especially useful in situations where entities have there own life-cycle.

This architecture can be used to develop applications for Xamarin.Forms, Xamarin.Android, Xamarin.iOS. It helps in seamless communication between various parts of the respective application models.

Build Status

Features

  • Attribute based API: Put the [EventSubscriber] attribute to your subscriber methods to mark it as a handler.
  • Good performance: It is optimized to dispatch events as soon as they posted.
  • Asynchronous event Delivery & Execution: All the event executions and delivery are asynchronous.
  • Event & Subscriber inheritance: In EventHub, the object oriented paradigm apply to event and subscriber classes. Let's say event class A is the superclass of B. Posted events of type B will also be posted to subscribers interested in A. Similarly the inheritance of subscriber classes are considered.
  • Main thread delivery: Using platform specific main thread invocation methods, you can also deliver UI changes to the application.
  • No 3rd party dependency: This is no Xamarin binding, thus no 3rd party dependency or binding difficulties.

Add EventHub to your Project

Nuget

โœจ โœจ The first stable version of the project is released ๐ŸŽ‰

Steps to use EventHub

  • Define classes for evevnts

        public class Event { /* Additional fields if needed */ }
  • Prepare subscribers: Declare and add attribute to your subscribing method

        [EventSubscriber]
        public void Subscriber(Event event) {/*Do Something*/}
  • Register and deregister your subscriber according to your lifecycle.

    For Xamarin.Android :

        protected override void OnAppearing()
        {
            base.OnAppearing();
            EventHub.Instance.Register(this);
        }
        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            EventHub.Instance.Deregister(this);
        }

    For Xamarin.iOS :

        public override void WillEnterForeground(UIApplication application)
        {
            EventHub.Instance.Register(this);
        }
        public override void DidEnterBackground(UIApplication application)
        {
            EventHub.Instance.Deregister(this);
        }

    For Xamarin.Forms :

        protected override void OnAppearing()
        {
            base.OnAppearing();
            EventHub.Instance.Register(this);
        }
        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            EventHub.Instance.Deregister(this);
        }
  • Post Events.

        EventHub.Instance.Post(new Event());

Main thread delivery

  • Xamarin.Android
        [EventSubscriber]
        public void OnEvent(string s)
        {
            new Handler(Looper.MainLooper).Post(() => {
                /* Do whatever you want on application UI thread*/ 
            });
        }
  • Xamarin.iOS
        [EventSubscriber]
        public void OnEvent(string s)
        {
            InvokeOnMainThread(()=> {
               /* Do whatever you want on application UI thread*/ 
            });
        }
  • Xamarin.Forms
        [EventSubscriber]
        public void OnEvent(string s)
        {
            Device.BeginInvokeOnMainThread(()=> {
               /* Do whatever you want on application UI thread*/ 
            });
        }

Future Scope

  1. Build time subscriber method template cache, so that run time performance stays unaffected.
  2. Assign batches for every event posted.
  3. Cancellation will depend on execution state of the batch.
  4. Priority based event posting.

License

EventHub binaries and source code can be used according to the Apache License 2.0.

eventhub's People

Contributors

hrupanjan 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.