Skip to content

Commit 39a25c0

Browse files
committed
Update README
1 parent a00a279 commit 39a25c0

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#### Why non-deterministic?
1717

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.
1919

2020
Use cases:
2121
* InsertCoin `transition to` Unlocked
@@ -64,9 +64,11 @@ Next, implement the `HAL.StateMachine<YourAction, YourState>` interface in your
6464

6565
The `HAL` class receives the following parameters:
6666
* 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))
6870
* 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
7072
- `action: A`: the action emitted to the state machine
7173
- `transitionTo: (S) -> Unit`: the function responsible for changing the state
7274

@@ -168,10 +170,10 @@ allprojects {
168170
2. Next, add the desired dependencies to your module:
169171
```gradle
170172
dependencies {
171-
// Core with default state observer
173+
// Core with callback state observer
172174
implementation "com.github.adrielcafe.hal:hal-core:$currentVersion"
173175
174-
// LiveData state observer
176+
// LiveData state observer only
175177
implementation "com.github.adrielcafe.hal:hal-livedata:$currentVersion"
176178
}
177179
```

hal-core/src/main/kotlin/cafe/adriel/hal/CallbackStateObserver.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import cafe.adriel.hal.HAL.State
44
import cafe.adriel.hal.HAL.StateObserver
55

66
class CallbackStateObserver<S : State>(
7-
override val observer: (S) -> Unit
7+
override val callback: (S) -> Unit
88
) : StateObserver<S> {
99

10-
override fun transitionTo(newState: S) = observer(newState)
10+
override fun transitionTo(newState: S) = callback(newState)
1111
}

hal-core/src/main/kotlin/cafe/adriel/hal/HAL.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class HAL<A : Action, S : State> (
5454

5555
interface StateObserver<S : State> {
5656

57-
val observer: (S) -> Unit
57+
val callback: (S) -> Unit
5858

5959
fun transitionTo(newState: S)
6060
}

hal-livedata/src/main/kotlin/cafe/adriel/hal/livedata/LiveDataStateObserver.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import cafe.adriel.hal.HAL.StateObserver
88

99
class LiveDataStateObserver<S : State>(
1010
lifecycleOwner: LifecycleOwner,
11-
override val observer: (S) -> Unit
11+
override val callback: (S) -> Unit
1212
) : StateObserver<S> {
1313

1414
private val liveData by lazy { MutableLiveData<S>() }
1515

1616
init {
17-
liveData.observe(lifecycleOwner, Observer(observer))
17+
liveData.observe(lifecycleOwner, Observer(callback))
1818
}
1919

2020
override fun transitionTo(newState: S) {

0 commit comments

Comments
 (0)