{"id":13606837,"url":"https://github.com/Rasalexman/KDispatcher","last_synced_at":"2025-04-12T11:30:54.991Z","repository":{"id":117999232,"uuid":"85979772","full_name":"Rasalexman/KDispatcher","owner":"Rasalexman","description":"Simple and light-weight event dispatcher for Kotlin","archived":false,"fork":false,"pushed_at":"2021-05-08T08:33:29.000Z","size":2021,"stargazers_count":66,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-07T12:41:20.675Z","etag":null,"topics":["android","android-architecture","android-library","event-driven","eventbus","kotlin","kotlin-android","kotlin-library"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rasalexman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-23T17:44:19.000Z","updated_at":"2023-10-11T17:59:00.000Z","dependencies_parsed_at":"2024-01-16T23:30:38.731Z","dependency_job_id":"36008e2c-6325-4987-8484-caf3a69d4a06","html_url":"https://github.com/Rasalexman/KDispatcher","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rasalexman%2FKDispatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rasalexman%2FKDispatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rasalexman%2FKDispatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rasalexman%2FKDispatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rasalexman","download_url":"https://codeload.github.com/Rasalexman/KDispatcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560047,"owners_count":21124583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-architecture","android-library","event-driven","eventbus","kotlin","kotlin-android","kotlin-library"],"created_at":"2024-08-01T19:01:12.883Z","updated_at":"2025-04-12T11:30:54.270Z","avatar_url":"https://github.com/Rasalexman.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# KDispatcher is a Kotlin EventDispatcher\n\n[![Kotlin 1.4.31](https://img.shields.io/badge/Kotlin-1.4.32-blue.svg)](http://kotlinlang.org) [![](https://jitpack.io/v/Rasalexman/KDispatcher.svg)](https://jitpack.io/#Rasalexman/KDispatcher) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f61b6230a3da404580250008f2e966b2)](https://app.codacy.com/app/Rasalexman/KDispatcher?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=Rasalexman/KDispatcher\u0026utm_campaign=Badge_Grade_Dashboard) [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin)\n\nThis is light-weight event dispatcher based on KOTLIN\n* `priority: Int? = null` to subscribe function for sorting\n* Inline function Included\n\nYou can subscribe on event by calling:\n```kotlin\nval EVENT_CALL_ONE = \"simple_event_name\"\nval eventListener = ::eventHandler\nval priority = 1\nKDispatcher.subscribe(EVENT_CALL_ONE, eventListener, priority)\n```\nwhere:\n* EVENT_CALL_ONE - simple event type  \n* eventListener - function listener for event \n* priority - the priority to sort calling functions \n\n```kotlin\n/**\n* notif:Notification\u003cT:Any\u003e - event holder object that store\n* data:T? = null - can be any type of data\n* eventName:String? = null - current event type\n* cause u may have more then one EVENT_TYPE for current event listener\n*/\nfun eventHandler(notif:Notification\u003cAny\u003e){\n  when(notif.eventName){\n      EVENT_CALL_ONE -\u003e println(\"FIRST EVENT\")\n  }\n}\n```\nOf course u can simpe call the event for all listeners by\n```kotlin\nval test:MyTestClass = MyTestClass()\nKDispatcher.call(EVENT_CALL_ONE, test)\n```\n\nDon't forget to unsubscribe your listeners when u dont need it anymore.\n```kotlin\nKDispatcher.unsubscribe(EVENT_CALL_ONE, eventListener)\n```\n\nSinse 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\u003cT:Any\u003e) -\u003e Unit` as event handlers\n```kotlin\nclass MainActivity : AppCompatActivity(), IKDispatcher {\n\n    private val eventListenerOne = this::eventOneHandler\n    //...\n    \n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        scopeOperation()\n    }\n    \n    private fun scopeOperation() {\n        // subscribe event to this handlers\n        subscribe(EVENT_CALL_ONE, eventListenerOne, 3)\n        subscribe(EVENT_CALL_ONE, ::eventListenerTwo, 1)\n        subscribe(EVENT_CALL_ONE, MyClass::eventListenerFour, 2)\n        // call event\n        call(EVENT_CALL_ONE, \"FIRST CALL FROM KDISPATCHER\")\n        \n        /**\n         * But you can simple use inner lambda function to handler notification.\n         * So as u hasn't a reference to ISubscriber handler function, when you call\n         * `usubscribe(String)` you will delete all references ISubscriber-listener\n         */\n        val eventName = \"LAMBDA_EVENT\"\n        subscribe\u003cString\u003e(eventName) { notification -\u003e\n            println(\"LAMBDA_EVENT HAS FIRED with event name ${notification.eventName} and data ${notification.data}\")\n            unsubscribe(notification.eventName)\n        }\n        \n        call(eventName, \"FIRST CALL CUSTOM LABDA EVENT\")\n        \n        /**\n        * Since version 0.1.7 you can subscribe by scope of events by a single callback\n        */\n        subscribeList\u003cAny\u003e(listOf(\"notif_one\", \"notif_two\")) {\n            when(it.eventName) {\n                \"notif_one\" -\u003e Toast.makeText(this, \"This is notif_one\", Toast.LENGTH_SHORT).show()\n                \"notif_two\" -\u003e Toast.makeText(this, \"This is notif_two\", Toast.LENGTH_SHORT).show()\n            }\n        }\n\n        call(\"notif_one\")\n        call(\"notif_two\")\n    }\n    \n    fun eventOneHandler(notification:Notification\u003cAny\u003e) {\n       println(\"eventOneHandler MY TEST IS COMING event = ${notification.eventName} AND data = ${notification.data}\")\n    }\n\n}\n```\n\nGradle: \n```kotlin\nimplementation 'com.rasalexman.kdispatcher:kdispatcher:x.y.z'\n```\n\nMaven:\n```kotlin\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.rasalexman.kdispatcher\u003c/groupId\u003e\n  \u003cartifactId\u003ekdispatcher\u003c/artifactId\u003e\n  \u003cversion\u003ex.y.z\u003c/version\u003e\n  \u003ctype\u003epom\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n* ThreadSafe\n* Simple\n* Usefull\n\n# License\n----\n\nMIT License\n\nCopyright (c) 2021 Alexandr Minkin (sphc@yandex.ru)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRasalexman%2FKDispatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRasalexman%2FKDispatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRasalexman%2FKDispatcher/lists"}