You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+46-61
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
# Kelm
2
2
3
-
Kelm eases the pain when dealing with complex app state and asynchronous tasks.
3
+
Kelm simplifies management of complex app states and asynchronous tasks.
4
+
4
5
Kelm is a Kotlin library based on the [Elm Architecture](https://guide.elm-lang.org/architecture) and [RxJava](http://reactivex.io/).
5
6
6
7
## Introduction
@@ -17,31 +18,39 @@ The **Model** can only be updated in the **Update** function. **Messages** are t
17
18
18
19
**Messages** can be UI events, responses from APIs, or the result of computations.
19
20
20
-
A good strategy when designing the initial version of a **Model** and **Messages** is to write down every event the UI can generate, and everything it can render.
21
-
22
21
### A simple example
23
22
24
23
Below is a simple Kelm app. Try to read and guess what it does:
The above example shows how the main flow of a Kelm app works.
54
-
We first declare our **Model** and our **Messages**, we then build the main **Update** function.
63
+
We first declare a `Kelm.Sandbox` object†, the contract for our **Model** and our **Messages**,
64
+
and how they interact with the **update** function.
65
+
66
+
† Your **Sandbox** implementation should be an **object** with no properties.
55
67
56
68
The **Update** is a *pure function* that takes the current **Model** and a **Message** and returns a new **Model**.
57
69
58
-
The return of the `Kelm::build` is of type `Observable<Model>`. The **View** (a Android View, for example) can subscribe to this `Observable` and render it when it changes.
70
+
The return of the `Element::start` is of type `Observable<Model>`.
71
+
The **View** (an Android View, for example) can subscribe to this `Observable` and render it when it changes.
59
72
60
-
See the [Counter Sample](sample-andorid/src/main/java/kelm/sample/CounterSampleActivity.kt) for a working implementation.
73
+
See the [Counter Sample](sample-android/src/main/java/kelm/sample/CounterSampleActivity.kt).
61
74
62
75
#### Rules for the **Update** function:
63
76
@@ -68,65 +81,37 @@ See the [Counter Sample](sample-andorid/src/main/java/kelm/sample/CounterSampleA
68
81
69
82
### Commands
70
83
71
-
**Commands** are asynchronous tasks that finish with *one***Message**.
84
+
**Commands** are asynchronous tasks that finish with *at most one***Message**.
72
85
This **Message** indicates the result of a task, be it a successful result
73
86
or an error.
74
87
75
-
Here's an example using commands to fetch data from an API:
88
+
* All side-effects and expensive computations must be done with **Commands**.
76
89
77
-
```kotlin
78
-
funfetchFromApi(): Single<Response> =...
90
+
To work with **Commands** implement an ``Kelm::Element`` instead of a ``Kelm::Sandbox``.
79
91
80
-
sealedclassModel {
81
-
object Loading : Model()
82
-
data classLoadedContent(valresponse:Response) : Model()
83
-
}
92
+
Then create a `cmdToMaybe` function that takes a **Command** and transforms it into a `Maybe<Msg>`.
93
+
This `Maybe<Msg>` is the action of a **Command** and *it should never emit any error in its error channel*.
84
94
85
-
sealedclassMsg {
86
-
object FetchClick : Msg()
87
-
data classContentFetched(valresponse:Response) : Msg()
88
-
}
95
+
The **Update** function has some special implicit functions like the `runCmd` function. `runCmd` adds the **Command** to be executed.
89
96
90
-
sealedclassCmd : kelm.Cmd() {
91
-
object FetchFromApi : Cmd()
92
-
}
97
+
See the [Fox Service Sample](sample-android/src/main/java/kelm/sample/FoxServiceSampleActivity.kt).
0 commit comments