ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - DavidMellul/Kotlin-Publish-Subscribe: 🦄Intuitive and powerful human-readable Kotlin DSL for IPCs & turning anything into a message receiver / broadcaster🦄
🦄Intuitive and powerful human-readable Kotlin DSL for IPCs & turning anything into a message receiver / broadcaster🦄 - DavidMellul/Kotlin-Publish-Subscribe
Visit Site

GitHub - DavidMellul/Kotlin-Publish-Subscribe: 🦄Intuitive and powerful human-readable Kotlin DSL for IPCs & turning anything into a message receiver / broadcaster🦄

GitHub - DavidMellul/Kotlin-Publish-Subscribe: 🦄Intuitive and powerful human-readable Kotlin DSL for IPCs & turning anything into a message receiver / broadcaster🦄

Kotlin-Publish-Subscribe

🦄Intuitive and powerful human-readable Kotlin DSL for IPCs & turning anything into a message receiver / broadcaster🦄

:white_check_mark: Seamless integration :white_check_mark: No dependencies :white_check_mark: No modification in your code & Powerful human-readable DSL :white_check_mark: Lightweight library ~ 1kb

Demonstration

Simple emitter - receiver

val alice = "Alice"
val bob = "Bob"

alice listenTo "message" then { print("I'm $alice and I have a new message\n") }
bob broadcast "message"

// Output : I'm Alice and I have a new message

Simple emitter - multiple receivers

val alice = "Alice"
val bryan = "Bryan"
val kevin = "Kevin"

val bob = "Bob"

listOf(alice,bryan,kevin).forEach { receiver -> receiver listenTo "message" then { print("$receiver has received Bob's message!\n") } }
bob broadcast "message"

// Output : 
Bryan has received Bob's message!
Kevin has received Bob's message!
Alice has received Bob's message!

Multiple emitters - Simple receiver

val julia = "Julia"

val bob = "Bob"
val fred = "Fred"
val tom = "Tom"

julia listenTo "seduction" then { print("Maybe another time fellow...\n")}
listOf(bob,fred,tom).forEach { it broadcast "seduction" }

// Output : 
Maybe another time fellow...
Maybe another time fellow...
Maybe another time fellow...

Emitter - Receiver with one parameter

val alice = "Alice"
val bob = "Bob"

alice listenTo "seduction" then { seductionLevel ->
            if( (seductionLevel as Int) > 9000)
                print("It's over 9k !!!!!")
            else
                print("Not enough...Keep doin' or die tryin'")
         }
        
bob broadcast SophisticatedSignal("seduction", 9001)

// Output : 
It's over 9k !!!!!

Emitter - Receiver with multiple parameters (not varargs ! Kotlin limitation :heart:)

val alice = "Alice"
val bob = "Bob"

alice listenTo "charming attempt" then { attempt ->
            print(attempt)
}

bob broadcast SophisticatedSignal("charming attempt",
                hashMapOf(
                        "Name" to "Boby Bob",
                        "Seduction level" to 100000,
                        "Height" to 1.7,
                        "Employment" to "Freelance Trainer & Developer ",
                        "Tasks to be done" to listOf("Pull", "Commit", "Push", "Leave the building"))
)
        
// Output
{Seduction level=100000, Height=1.7, Tasks to be done=[Pull, Commit, Push, Leave the building], Employment=Freelance Trainer & Developer , Name=Boby Bob}

Emitter - Receiver with one parameter and usage of stopListenTo

val alice = "Alice"
val bob = "Bob"

alice listenTo "message" then { message ->
    print("Bob: $message\n")
    alice broadcast SophisticatedSignal("reply", "Wassup bro")
}

bob listenTo "reply" then { reply ->
    print("Alice : $reply\n")
    print("(Bob thinking) I will break up with her hahaha ! First block her\n")
    bob stopListenTo "reply"
    print("(Bob thinking) Ok done !\n")
    bob broadcast SophisticatedSignal("message", "Godd bye !")
}

bob broadcast SophisticatedSignal("message", "Hello Alice !")

// Output :
Bob: Hello Alice !
Alice : Wassup bro
(Bob thinking)I will break up with her hahaha ! First block her
(Bob thinking) Ok done !
Bob: Godd bye !

Install

Gradle

First add the Jitpack repository in your root build.gradle at the end of repositories:

allprojects {
   	repositories {
   		...
   		maven { url 'https://jitpack.io' }
   	}
   }
 

Then, copy paste this line into your dependencies

compile 'com.github.DavidMellul:Kotlin-Publish-Subscribe:-SNAPSHOT'

Maven

Add the Jitpack repository to your pom.xml

<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
</repositories>

Then, add the dependency

<dependency>
	    <groupId>com.github.DavidMellul</groupId>
	    <artifactId>Kotlin-Publish-Subscribe</artifactId>
	    <version>-SNAPSHOT</version>
</dependency>

SBT

Add both lines to your build.sbt

resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.DavidMellul" % "Kotlin-Publish-Subscribe" % "-SNAPSHOT"	

Use case

You could use this lightweight library in such cases:

  • Asynchronous treatments
  • Communication between independant objects
  • Observer-Observable design-pattern
  • Basically everything that requires that both entities communicate so that one reacts to another

Documentation

The library has been created with Kotlin and has no external dependencies. It means it is fully interoperable with Java ! :purple_heart:

:sparkling_heart: This library is dead easy to use -> Look at the examples in the demonstration :sparkling_heart:

:triangular_flag_on_post: This library works only with the Any supertype ==> It means you can turn absolutely everything into a broadcaster / receiver and put everything as parameter associated to a signal. :triangular_flag_on_post:

Contribute

Feel free to:

  • Open issues / pull requests if there is any bug / missing feature. :love_letter:
  • Star this repo :unicorn:
  • Ask for a :coffee:

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory