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
{{ message }}
This repository was archived by the owner on Apr 19, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+26-24Lines changed: 26 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,49 @@
1
-
# TODO-MVI-RxJava
1
+
# TODO-MVI-RxJava-Kotlin
2
+
3
+
### Java Version
4
+
5
+
You can fin the Java version of this app [here](https://github.com/oldergod/android-architecture/tree/todo-mvi-rxjava).
2
6
3
7
### Contributors
4
8
5
-
[Benoît Quenaudon](https://github.com/oldergod) and [David González](https://github.com/malmstein).
9
+
[Benoît Quenaudon](https://github.com/oldergod)
6
10
7
11
### Summary
8
12
9
-
This version of the app is called TODO-MVI-RxJava. It is based on an Android ported version of the Model-View-Intent architecture and uses RxJava to implement the reactive caracteristic of the architecture. It is initially a fork of the [TODO-MVP-RXJAVA](https://github.com/googlesamples/android-architecture/tree/todo-mvp-rxjava).
13
+
This version of the app is called TODO-MVI-RxJava-Kotlin. It is based on an Android ported version of the Model-View-Intent architecture and uses RxJava to implement the reactive caracteristic of the architecture. It is initially a fork of the [TODO-MVP-RXJAVA](https://github.com/googlesamples/android-architecture/tree/todo-mvp-rxjava).
10
14
11
15
The MVI architecture embraces reactive and functional programming. The two main components of this architecture, the _View_ and the _ViewModel_ can be seen as functions, taking an input and emiting outputs to each other. The _View_ takes input from the _ViewModel_ and emit back _intents_. The _ViewModel_ takes input from the _View_ and emit back _view states_. This means the _View_ has only one entry point to forward data to the _ViewModel_ and vice-versa, the _ViewModel_ only has one way to pass information to the _View_.
12
16
This is reflected in their API. For instance, The _View_ has only two exposed methods:
13
17
14
-
```java
15
-
publicinterfaceMviView {
16
-
Observable<MviIntent>intents();
18
+
```kotlin
19
+
interfaceMviView {
20
+
funintents(): Observable<MviIntent>
17
21
18
-
voidrender(MviViewStatestate);
22
+
funrender(state:MviViewState)
19
23
}
20
24
```
21
25
22
26
A _View_ will a) emit its intents to a _ViewModel_, and b) subscribes to this _ViewModel_ in order to receive _states_ needed to render its own UI.
23
27
24
28
A _ViewModel_ exposes only two methods as well:
25
29
26
-
```java
27
-
publicinterfaceMviViewModel {
28
-
voidprocessIntents(Observable<MviIntent>intents);
30
+
```kotlin
31
+
interfaceMviViewModel {
32
+
funprocessIntents(intents:Observable<MviIntent>)
29
33
30
-
Observable<MviViewState>states();
34
+
funstates(): Observable<MviViewState>
31
35
}
32
36
```
33
37
34
38
A _ViewModel_ will a) process the _intents_ of the _View_, and b) emit a _view state_ back so the _View_ can reflect the change, if any.
35
39
36
-
<imgsrc="https://raw.githubusercontent.com/oldergod/android-architecture/todo-mvi-rxjava/art/MVI_global.png"alt="View and ViewModel are simple functions."/>
40
+
<imgsrc="https://raw.githubusercontent.com/oldergod/android-architecture/todo-mvi-rxjava-kotlin/art/MVI_global.png"alt="View and ViewModel are simple functions."/>
37
41
38
42
### The User is a function
39
43
40
44
The MVI architecture sees the user as part of the data flow, a functionnal component taking input from the previous one and emitting event to the next. The user receives an input―the screen from the application―and ouputs back events (touch, click, scroll...). On Android, the input/output of the UI is at the same place; either physically as everything goes through the screen or in the program: I/O inside the activity or the fragment. Including the User to seperate the input of the view from its output helps keeping the code healty.
41
45
42
-
<imgsrc="https://raw.githubusercontent.com/oldergod/android-architecture/todo-mvi-rxjava/art/MVI_detail.png"alt="Model-View-Intent architecture in details"/>
46
+
<imgsrc="https://raw.githubusercontent.com/oldergod/android-architecture/todo-mvi-rxjava-kotlin/art/MVI_detail.png"alt="Model-View-Intent architecture in details"/>
43
47
44
48
### MVI in details
45
49
@@ -80,19 +84,18 @@ The _State_ contains all the information the _View_ needs to render itself.
80
84
81
85
The `TasksDataSource` interface contains methods like:
82
86
83
-
```java
84
-
Single<List<Task>> getTasks();
87
+
```kotlin
88
+
fungetTasks(): Single<List<Task>>
85
89
86
-
Single<Task> getTask(@NonNullString taskId);
90
+
fungetTask(taskId:String): Single<Task>
87
91
88
-
Completable completeTask(@NonNullTask task);
92
+
funcompleteTask(task:Task): Completable
89
93
```
90
94
91
95
This is implemented in `TasksLocalDataSource` with the help of [SqlBrite](https://github.com/square/sqlbrite). The result of queries to the database being easily exposed as streams of data.
@@ -106,7 +109,7 @@ Handling of the working threads is done with the help of RxJava's `Scheduler`s.
106
109
107
110
### Immutability
108
111
109
-
Data immutability is embraced to help keeping the logic simple. Immutability means that we do not need to manage data being mutated in other methods, in other threads, etc; because we are sure the data cannot change. Data immutability is implemented with the help of [AutoValue](https://github.com/google/auto/tree/master/value). Our all value objects are interfaces of which AutoValue will generate the implementation.
112
+
Data immutability is embraced to help keeping the logic simple. Immutability means that we do not need to manage data being mutated in other methods, in other threads, etc; because we are sure the data cannot change. Data immutability is implemented with Kotlin's `data class`.
110
113
111
114
### Functional Programming
112
115
@@ -122,7 +125,6 @@ We use the [Architecture Components library](https://developer.android.com/topic
Copy file name to clipboardExpand all lines: app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/custom/action/NavigationViewActions.java
0 commit comments