All Projects → Rasalexman → KDispatcher

Rasalexman / KDispatcher

Licence: other
Simple and light-weight event dispatcher for Kotlin

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to KDispatcher

evon
Fast and versatile event dispatcher code generator for Golang
Stars: ✭ 15 (-76.56%)
Mutual labels:  eventbus, event-driven
Run Aspnetcore Microservices
Microservices on .Net platforms which used Asp.Net Web API, Docker, RabbitMQ, MassTransit, Grpc, Ocelot API Gateway, MongoDB, Redis, PostgreSQL, SqlServer, Dapper, Entity Framework Core, CQRS and Clean Architecture implementation. Also includes Cross-Cutting concerns like Implementing Centralized Distributed Logging with Elasticsearch, Kibana and SeriLog, use the HealthChecks with Watchdog, Implement Retry and Circuit Breaker patterns with Polly and so on.. See Microservices Architecture and Step by Step Implementation on .NET Course w/ discount->
Stars: ✭ 406 (+534.38%)
Mutual labels:  eventbus, event-driven
EventBus
A .NET Core ultra lightweight in-memory event bus implementation.
Stars: ✭ 73 (+14.06%)
Mutual labels:  eventbus, event-driven
IntroduceToEclicpseVert.x
This repository contains the code of Vert.x examples contained in my articles published on platforms such as kodcu.com, medium, dzone. How to run each example is described in its readme file.
Stars: ✭ 27 (-57.81%)
Mutual labels:  eventbus, event-driven
Fluxxan
Fluxxan is an Android implementation of the Flux Architecture that combines concepts from both Fluxxor and Redux.
Stars: ✭ 80 (+25%)
Mutual labels:  eventbus, android-architecture
reacted
Actor based reactive java framework for microservices in local and distributed environment
Stars: ✭ 17 (-73.44%)
Mutual labels:  eventbus, event-driven
Eventline
Micro-framework for routing and handling events for bots and applications 🤖. IFTTT for developers 👩‍💻👨‍💻
Stars: ✭ 305 (+376.56%)
Mutual labels:  eventbus, event-driven
Mbassador
Powerful event-bus optimized for high throughput in multi-threaded applications. Features: Sync and Async event publication, weak/strong references, event filtering, annotation driven
Stars: ✭ 877 (+1270.31%)
Mutual labels:  eventbus, event-driven
Asombroso Ddd
Una lista cuidadosamente curada de recursos sobre Domain Driven Design, Eventos, Event Sourcing, Command Query Responsibility Segregation (CQRS).
Stars: ✭ 41 (-35.94%)
Mutual labels:  eventbus, event-driven
Flair
This is powerful android framework
Stars: ✭ 31 (-51.56%)
Mutual labels:  eventbus, android-architecture
Rabbus
A tiny wrapper over amqp exchanges and queues 🚌 ✨
Stars: ✭ 86 (+34.38%)
Mutual labels:  eventbus, event-driven
Resugan
simple, powerful and unobstrusive event driven architecture framework for ruby
Stars: ✭ 82 (+28.13%)
Mutual labels:  eventbus, event-driven
azeroth-event
Lightweight event-driven framework
Stars: ✭ 18 (-71.87%)
Mutual labels:  eventbus, event-driven
Eventbus
C# 事件总线实现
Stars: ✭ 127 (+98.44%)
Mutual labels:  eventbus
Bus
🔊Minimalist message bus implementation for internal communication
Stars: ✭ 187 (+192.19%)
Mutual labels:  eventbus
Milkomeda
Spring extend componets which build from experience of bussiness, let developers to develop with Spring Boot as fast as possible.(基于Spring生态打造的一系列来自业务上的快速开发模块集合。)
Stars: ✭ 117 (+82.81%)
Mutual labels:  eventbus
Rxbus2
RxJava2 based bus with queuing (e.g. lifecycle based) support
Stars: ✭ 116 (+81.25%)
Mutual labels:  eventbus
WizardX
Fast build efficient Android: Fast building, high quality, and efficient Android App infrastructure scaffolding right out of the box(快速构建、高质量、高效率Android App应用开箱即用的基础脚手架)
Stars: ✭ 115 (+79.69%)
Mutual labels:  android-architecture
Messagebus
A MessageBus (CommandBus, EventBus and QueryBus) implementation in PHP7
Stars: ✭ 178 (+178.13%)
Mutual labels:  eventbus
Cscore
cscore is a minimal-footprint library providing commonly used helpers & patterns for your C# projects. It can be used in both pure C# and Unity projects.
Stars: ✭ 115 (+79.69%)
Mutual labels:  eventbus

KDispatcher is a Kotlin EventDispatcher

Kotlin 1.4.31 Codacy Badge Awesome Kotlin Badge

This is light-weight event dispatcher based on KOTLIN

  • priority: Int? = null to subscribe function for sorting
  • Inline function Included

You can subscribe on event by calling:

val EVENT_CALL_ONE = "simple_event_name"
val eventListener = ::eventHandler
val priority = 1
KDispatcher.subscribe(EVENT_CALL_ONE, eventListener, priority)

where:

  • EVENT_CALL_ONE - simple event type
  • eventListener - function listener for event
  • priority - the priority to sort calling functions
/**
* notif:Notification<T:Any> - event holder object that store
* data:T? = null - can be any type of data
* eventName:String? = null - current event type
* cause u may have more then one EVENT_TYPE for current event listener
*/
fun eventHandler(notif:Notification<Any>){
  when(notif.eventName){
      EVENT_CALL_ONE -> println("FIRST EVENT")
  }
}

Of course u can simpe call the event for all listeners by

val test:MyTestClass = MyTestClass()
KDispatcher.call(EVENT_CALL_ONE, test)

Don't forget to unsubscribe your listeners when u dont need it anymore.

KDispatcher.unsubscribe(EVENT_CALL_ONE, eventListener)

Sinse version 0.1.2 you can use extension and inline functions of KDispatcher. All you need to do is implement IKDispatcher interface. Also you can use single lambda functions like (Notification<T:Any>) -> Unit as event handlers

class MainActivity : AppCompatActivity(), IKDispatcher {

    private val eventListenerOne = this::eventOneHandler
    //...
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        scopeOperation()
    }
    
    private fun scopeOperation() {
        // subscribe event to this handlers
        subscribe(EVENT_CALL_ONE, eventListenerOne, 3)
        subscribe(EVENT_CALL_ONE, ::eventListenerTwo, 1)
        subscribe(EVENT_CALL_ONE, MyClass::eventListenerFour, 2)
        // call event
        call(EVENT_CALL_ONE, "FIRST CALL FROM KDISPATCHER")
        
        /**
         * But you can simple use inner lambda function to handler notification.
         * So as u hasn't a reference to ISubscriber handler function, when you call
         * `usubscribe(String)` you will delete all references ISubscriber-listener
         */
        val eventName = "LAMBDA_EVENT"
        subscribe<String>(eventName) { notification ->
            println("LAMBDA_EVENT HAS FIRED with event name ${notification.eventName} and data ${notification.data}")
            unsubscribe(notification.eventName)
        }
        
        call(eventName, "FIRST CALL CUSTOM LABDA EVENT")
        
        /**
        * Since version 0.1.7 you can subscribe by scope of events by a single callback
        */
        subscribeList<Any>(listOf("notif_one", "notif_two")) {
            when(it.eventName) {
                "notif_one" -> Toast.makeText(this, "This is notif_one", Toast.LENGTH_SHORT).show()
                "notif_two" -> Toast.makeText(this, "This is notif_two", Toast.LENGTH_SHORT).show()
            }
        }

        call("notif_one")
        call("notif_two")
    }
    
    fun eventOneHandler(notification:Notification<Any>) {
       println("eventOneHandler MY TEST IS COMING event = ${notification.eventName} AND data = ${notification.data}")
    }

}

Gradle:

implementation 'com.rasalexman.kdispatcher:kdispatcher:x.y.z'

Maven:

<dependency>
  <groupId>com.rasalexman.kdispatcher</groupId>
  <artifactId>kdispatcher</artifactId>
  <version>x.y.z</version>
  <type>pom</type>
</dependency>
  • ThreadSafe
  • Simple
  • Usefull

License


MIT License

Copyright (c) 2021 Alexandr Minkin ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].