Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10 from ibrahimyilmaz/feature/change_readme_for_n…
Browse files Browse the repository at this point in the history
…onnull_observe

Feature/change readme for nonnull observe
  • Loading branch information
ibrahimyilmaz authored Jul 20, 2019
2 parents f4878ce + be5e32b commit 6d665f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Changelog

## [Unreleased]
## [Development]
- ChangeLog updated for Non Null Observe.

## Bursa(0.0.2)
- Non Null Observe extension method is added.

## Bursa(0.0.1)
- Bintray Publish
- PublishLiveData and ReplayLiveData implemented
Expand Down
47 changes: 35 additions & 12 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ArchData
=======

ArchData provides two missing LiveData of Android Lifecycle Component.
ArchData provides two missing LiveData of Android Lifecycle Component and useful extension functions.

`MutableLiveData` shares only last state to its new observers when they start to observe.

Expand All @@ -15,6 +15,10 @@ Basically:
* `PublishLiveData` is `MutableLiveData`, which only notify its observers if there is an event after their starting of observation.
* `ReplayLiveData` is `MutableLiveData`, which only notify its observers for all previous events happened before their observation starts.

Extension Functions:

* `nonNullObserve` is extension function, which eliminates nullable invokes of Observer.


Usage
-----
Expand All @@ -27,27 +31,46 @@ Usage
```kotlin
val liveData = PublishLiveData<String>();
// observer1 will receive all events
liveData.observe(lifeCycleOwner,observer1);
liveData.postValue("one");
liveData.postValue("two");
liveData.observe(lifeCycleOwner,observer1)
liveData.postValue("one")
liveData.postValue("two")
// observer2 will only receive "three"
liveData.observe(lifeCycleOwner,observer2);
liveData.postValue("three");
liveData.observe(lifeCycleOwner,observer2)
liveData.postValue("three")
```

* **`ReplayLiveData`**

LiveData that buffers all items it observes and replays them to any `Observer` that subscribes.

```kotlin
val liveData = ReplayLiveData<String>();
liveData.postValue("one");
liveData.postValue("two");
liveData.postValue("three");
val liveData = ReplayLiveData<String>()
liveData.postValue("one")
liveData.postValue("two")
liveData.postValue("three")
// both of the following will get the events from above
liveData.observe(lifeCycleOwner,observer1);
liveData.postValue(lifeCycleOwner,observer2);
liveData.observe(lifeCycleOwner,observer1)
liveData.postValue(lifeCycleOwner,observer2)
```

* **`nonNullObserve`**

LiveData that buffers all items it observes and replays them to any `Observer` that subscribes.

```kotlin

val liveData = MutableLiveData<String>()
...

viewModel.liveData.nonNullObserve(lifeCycleOwner,::onLiveDataEvent)

...

fun onLiveDataEvent(event: String){
//Do something good!.
}

```

Download
--------
Expand Down

0 comments on commit 6d665f0

Please sign in to comment.