|
15 | 15 |
|
16 | 16 | #### Why non-deterministic?
|
17 | 17 |
|
18 |
| -In a [non-deterministic](https://www.tutorialspoint.com/automata_theory/non_deterministic_finite_automaton.htm) finite-state machine, an action can lead to *one*, *more than one*, or *no transition* for a given state. |
| 18 | +Because in a [non-deterministic](https://www.tutorialspoint.com/automata_theory/non_deterministic_finite_automaton.htm) finite-state machine, an action can lead to *one*, *more than one*, or *no transition* for a given state. That way we have more flexibility to handle any kind of scenario. |
19 | 19 |
|
20 | 20 | Use cases:
|
21 | 21 | * InsertCoin `transition to` Unlocked
|
@@ -64,9 +64,11 @@ Next, implement the `HAL.StateMachine<YourAction, YourState>` interface in your
|
64 | 64 |
|
65 | 65 | The `HAL` class receives the following parameters:
|
66 | 66 | * A [`CoroutineScope`](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/) (tip: use the [built in viewModelScope](https://developer.android.com/topic/libraries/architecture/coroutines#viewmodelscope))
|
67 |
| -* A initial state |
| 67 | +* An initial state |
| 68 | +* An *optional* capacity to specify the [Channel buffer size](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html) (default is [Channel.UNLIMITED](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-u-n-l-i-m-i-t-e-d.html)) |
| 69 | +* An *optional* [CoroutineDispatcher](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html) to run the reducer function (default is [Dispatcher.DEFAULT](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html)) |
68 | 70 | * A reducer function, `suspend (action: A, transitionTo: (S) -> Unit) -> Unit`, where:
|
69 |
| - - `suspend`: the reducer runs inside a coroutine scope on a [default dispatcher](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/), so you can run IO and other complex tasks without worrying about block the Main Thread |
| 71 | + - `suspend`: the reducer runs inside a `CoroutineScope`, so you can run IO and other complex tasks without worrying about block the Main Thread |
70 | 72 | - `action: A`: the action emitted to the state machine
|
71 | 73 | - `transitionTo: (S) -> Unit`: the function responsible for changing the state
|
72 | 74 |
|
@@ -168,10 +170,10 @@ allprojects {
|
168 | 170 | 2. Next, add the desired dependencies to your module:
|
169 | 171 | ```gradle
|
170 | 172 | dependencies {
|
171 |
| - // Core with default state observer |
| 173 | + // Core with callback state observer |
172 | 174 | implementation "com.github.adrielcafe.hal:hal-core:$currentVersion"
|
173 | 175 |
|
174 |
| - // LiveData state observer |
| 176 | + // LiveData state observer only |
175 | 177 | implementation "com.github.adrielcafe.hal:hal-livedata:$currentVersion"
|
176 | 178 | }
|
177 | 179 | ```
|
|
0 commit comments