Skip to content

Commit

Permalink
Merge pull request #58 from RedMadRobot/AND-147-comment-fixes
Browse files Browse the repository at this point in the history
AND-147: additional fixes
  • Loading branch information
EmogurovAnton authored Jul 31, 2024
2 parents f7f4116 + f766d7d commit 54b6857
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 36 deletions.
4 changes: 4 additions & 0 deletions ktx/lifecycle-livedata-ktx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

### Changes

- **Breaking change!** `EventQueue` has been moved to a separate module and renamed to `ViewModelEvents`. See the appropriate [documentation](../../viewmodelevents/README.md)

### Dependencies

- androidx.activity 1.2.3 -> 1.3.1
Expand Down
31 changes: 0 additions & 31 deletions ktx/lifecycle-livedata-ktx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Extended set of extensions for dealing with `LiveData`.
- [Installation](#installation)
- [Usage](#usage)
- [`LiveData` delegate](#livedata-delegate)
- [ViewModelEvents](#viewmodelevents)
- [Contributing](#contributing)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -60,36 +59,6 @@ val liveData = MutableLiveData<SomeViewState>(initialState)
var state: SomeViewState by liveData
```

### ViewModelEvents

`LiveData` stores only last value, so it is unusable for storing events.
All events should be added to some kind of buffer and emitted on call `LiveData.observe`.
`ViewModelEvents` implemented via `LiveData` fits these needs.

You can observe it like a normal `LiveData` and it will add to buffer all events you passed into:

```kotlin
data class MessageEvent(val message: String) : Event

val viewModelEvents = ViewModelEvents()

viewModelEvents.offerEvent(MessageEvent("A"))
viewModelEvents.offerEvent(MessageEvent("B"))
viewModelEvents.observeForever { println(it) }
viewModelEvents.offerEvent(MessageEvent("C"))
```

```kotlin
MessageEvent(message="A")
MessageEvent(message="B")
MessageEvent(message="C")
```

| Extension | Description |
|-----------|-------------|
| <pre><code>Fragment.observe(<br> liveData: EventQueue,<br> onEvent: (Event) -> Unit<br>)</code></pre> | Shorter way to observe `LiveData` in a fragment |
| <pre><code>ComponentActivity.observe(<br> liveData: EventQueue,<br> onEvent: (Event) -> Unit<br>)</code></pre> | Shorter way to observe `LiveData` in an activity |

## Contributing

Merge requests are welcome.
Expand Down
2 changes: 1 addition & 1 deletion viewmodelevents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

*No changes*

## 1.0.0 - 2024.05.14
## 1.0.0

- Public release viewModelEvents libraries
8 changes: 4 additions & 4 deletions viewmodelevents/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ViewModelEvents <GitHub path="RedMadRobot/gears-android/tree/main/ktx/viewmodel-events-ktx"/>
[![Version](https://img.shields.io/maven-central/v/com.redmadrobot.eventqueue/eventqueue-livedata?style=flat-square)][mavenCentral]
[![License](https://img.shields.io/github/license/RedMadRobot/EventQueue?style=flat-square)][license]
# ViewModelEvents
[![Version](https://img.shields.io/maven-central/v/com.redmadrobot.viewmodelevents/viewmodelevents-common?style=flat-square)][mavenCentral]
[![License](https://img.shields.io/github/license/RedMadRobot/gears-android?style=flat-square)][license]

The entity to handle one-time viewModel events.

Expand Down Expand Up @@ -190,5 +190,5 @@ fun EventsDispatcher.showError(message: String) {
Merge requests are welcome.
For major changes, please open an issue first to discuss what you would like to change.

[mavenCentral]: https://search.maven.org/artifact/com.redmadrobot.eventqueue/eventqueue-livedata
[mavenCentral]: https://central.sonatype.com/artifact/com.redmadrobot.viewmodelevents/viewmodelevents-common
[license]: ../LICENSE

0 comments on commit 54b6857

Please sign in to comment.