Skip to content

Commit 9fb5735

Browse files
Create README.md
1 parent e51c906 commit 9fb5735

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# stateflow-flow-sharedflow-livedata
2+
Basic app to use different type of observables StateFlow, Flow, SharedFlow, LiveData, State, Channel...
3+
4+
**StateFlow, Flow, SharedFlow, LiveData**
5+
6+
<a href="https://github.com/raheemadamboev/stateflow-flow-sharedflow-livedata/blob/master/app-debug.apk">Demo app</a>
7+
8+
**LiveData**
9+
10+
LiveData is an lifecycle aware observable data holder ( means it knows the lifecycle of the activity or an fragment) use it when you play with UI elements(views).
11+
12+
<img src="https://github.com/raheemadamboev/stateflow-flow-sharedflow-livedata/blob/master/screenshot-livedata.gif" alt="Italian Trulli" width="296" height="576">
13+
14+
**StateFlow**
15+
16+
StateFlow(hot stream) does similar things like LiveData but it is made using flow by kotlin guys and only difference compare to LiveData is its not lifecycle aware but this is also been solved using repeatOnLifecycle api's, So whatever LiveData can do StateFlow can do much better with power of flow's api. StateFlow won't emit same value.
17+
18+
<img src="https://github.com/raheemadamboev/stateflow-flow-sharedflow-livedata/blob/master/screenshot-stateflow.gif" alt="Italian Trulli" width="296" height="576">
19+
20+
**Flow**
21+
22+
Flow (cold stream) - In general think of it like a stream of data flowing in a pipe with both ends having a producer and consumer running on a coroutine.
23+
24+
<img src="https://github.com/raheemadamboev/stateflow-flow-sharedflow-livedata/blob/master/screenshot-flow.gif" alt="Italian Trulli" width="296" height="576">
25+
26+
**SharedFlow**
27+
28+
SharedFlow(hot stream) - name itself says it is shared, this flow can be shared by multiple consumers, I mean if multiple collect calls happening on the sharedflow there will be a single flow which will get shared across all the consumers unlike normal flow.
29+
30+
<img src="https://github.com/raheemadamboev/stateflow-flow-sharedflow-livedata/blob/master/screenshot-sharedflow.gif" alt="Italian Trulli" width="296" height="576">
31+
32+
**Channel**
33+
34+
SharedFlow as a hot flow will emit data even if no one listening. Channel will hold data till someone consumes it. So if your view not ready to receive an event and sharedFlow emits it, the event will be lost. So channels are better to send one time events. Obviously you can set reply count for shared flow, but then your event will be repeated .
35+
36+
**Tech stack:**
37+
38+
- Dependency Injection (Hilt)
39+
- Kotlin Coroutines
40+
- Flow
41+
- StateFlow
42+
- SharedFlow
43+
- LiveData
44+
- ViewModel

0 commit comments

Comments
 (0)