https://github.com/zhuinden/live-event
[ACTIVE] Lifecycle-aware wrapper over EventEmitter, for modelling one-off events.
https://github.com/zhuinden/live-event
Last synced: about 1 month ago
JSON representation
[ACTIVE] Lifecycle-aware wrapper over EventEmitter, for modelling one-off events.
- Host: GitHub
- URL: https://github.com/zhuinden/live-event
- Owner: Zhuinden
- License: apache-2.0
- Created: 2020-08-27T18:16:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-24T03:40:26.000Z (over 1 year ago)
- Last Synced: 2025-04-01T15:41:04.185Z (2 months ago)
- Language: Kotlin
- Homepage:
- Size: 116 KB
- Stars: 63
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Live-Event
The `LiveEvent` helper class allows you to observe events from an `EventEmitter` with a lifecycle-aware observer.
Using the `LifecycleOwner` passed to `observe`, it will automatically stop listening when the Lifecycle is destroyed.
You can only emit events and listen for events on the thread where you created the `EventEmitter`.
## Example
``` kotlin
// write
private val emitter: EventEmitter = EventEmitter()
val events: EventSource = emitterfun doSomething() {
emitter.emit("hello")
}// read
fun observe() {
events.observe(lifecycleOwner) { event ->
showToast(event)
}
}
```## Using Live Event
In order to use Live Event, you need to add jitpack to your project root gradle:
buildscript {
repositories {
// ...
maven { url "https://jitpack.io" }
}
// ...
}
allprojects {
repositories {
// ...
maven { url "https://jitpack.io" }
}
// ...
}In newer projects, you need to also update the `settings.gradle` file's `dependencyResolutionManagement` block:
```
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // <--
jcenter() // Warning: this repository is going to shut down soon
}
}
```and add the compile dependency to your module level gradle.
implementation 'com.github.Zhuinden:live-event:1.4.0'
## License
Copyright 2020 Gabor Varadi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.