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
Mini is a minimal Flux architecture written in Kotlin that also adds a mix of useful features to build UIs fast.
3
5
4
6
### Purpose
5
7
You should use this library if you aim to develop a reactive application with good performance (no reflection using code-gen).
6
8
Feature development using Mini is fast compared to traditional architectures (like CLEAN or MVP), low boilerplate and state based models make feature integration and bugfixing easy as well as removing several families of problems like concurrency or view consistency across screens.
7
9
8
-
## How to Use
9
-
### Actions
10
+
### How to Use
11
+
## Dispatcher
12
+
The *Dispatcher* is the hub that manages all data flow in a Flux application. It is basically a holder of store callbacks: each store registers itself and provides a callback for an action.
10
13
11
-
🚧WIP🚧
14
+
One important thing is that the dispatching is always performed in the same thread to avoid possible side-effects.
12
15
13
-
### Dispatcher
14
-
15
-
🚧WIP🚧
16
+
We can dispatch actions in the following ways:
16
17
17
18
```kotlin
18
-
//Dispatch an action on the main thread synchronously
19
+
//Dispatch an action on the main thread synchronously
The Stores are holders for application state and state mutation logic. In order to do so they expose pure reducer functions that are later invoked by the dispatcher.
26
+
## Store
27
+
The *Stores* are holders for application state and state mutation logic. In order to do so they expose pure reducer functions that are later invoked by the dispatcher.
27
28
28
-
The state is plain object (usually a data class) that holds all information needed to display the view. State should always be inmutable. State classes should avoid using framework elements (View, Camera, Cursor...) in order to facilitate testing.
29
+
The state is a plain object (usually a `data class`) that holds all information needed to display the view. States should always be inmutable. State classes should avoid using framework elements (View, Camera, Cursor...) in order to facilitate testing.
29
30
30
31
Stores subscribe to actions to change the application state after a dispatch. Mini generates the code that links dispatcher actions and stores using the `@Reducer` annotation over a **non-private function that receives an Action as parameter**.
31
32
32
-
🚧WIP🚧
33
+
```kotlin
34
+
data classSessionState(valloginTask:Task = taskIdle(), valloggedUser:User? = null)
An *Action* is a simple class that usually represents a use case. It can also contain a payload that includes data to perform said action. When an action is triggered, it will be delivered via dispatcher to the stores that are going to do something with the action to change their state.
52
+
53
+
For example, we may want to log in to a service. We would create an action like this one:
54
+
```kotlin
55
+
data classLoginAction(valusername:String, valpassword:String)
56
+
```
33
57
34
-
### Generated code
58
+
When we receive the response from the server, we'll dispatch another action with the result:
59
+
```kotlin
60
+
data classLoginCompleteAction(valloginTask:Task, valuser:User?)
61
+
```
62
+
63
+
Actions will usually be triggered from Views or Controllers.
64
+
65
+
## Generated code
35
66
36
67
🚧WIP🚧
37
68
38
-
###View changes
39
-
Each ``Store`` exposes a custom `StoreCallback` though the method `observe` or a `Flowable` if you wanna make use of RxJava. Both of them emits changes produced on their states, allowing the view to listen reactive the state changes. Being able to update the UI according to the new `Store` state.
69
+
## View changes
70
+
Each ``Store`` exposes a custom `StoreCallback` though the method `observe` or a `Flowable` if you want to make use of RxJava. Both of them emits changes produced on their states, allowing the view to listen reactive the state changes. Being able to update the UI according to the new `Store` state.
40
71
41
72
```kotlin
42
73
//Using RxJava
@@ -52,31 +83,10 @@ Each ``Store`` exposes a custom `StoreCallback` though the method `observe` or a
52
83
53
84
If you make use of the RxJava methods, you can make use of the `SubscriptionTracker` interface to keep track of the `Disposables` used on your activities and fragments.
54
85
55
-
###Tasks
86
+
## Tasks
56
87
A Task is a basic object to represent an ongoing process. They should be used in the state of our `Store` to represent ongoing processes that must be represented in the UI.
57
-
Having the next code:
58
-
59
-
```kotlin
60
-
data classLoginAction(valusername:String, valpassword:String)
61
-
data classLoginCompleteAction(valloginTask:Task, valuser:User?)
62
-
```
63
-
```kotlin
64
-
data classSessionState(valloginTask:Task = taskIdle(), valloggedUser:User? = null)
Given the example Stores and Actions explained before, the workflow will be:
80
90
81
91
- View dispatch `LoginAction`.
82
92
- Store changes his `LoginTask` status to running and call though his SessionController which will do all the async work to log in the given user.
@@ -85,7 +95,7 @@ The workflow will be:
85
95
- The Store changes his state to the given values from `LoginCompleteAction`.
86
96
- The View redirect to the HomeActivity if the task was success or shows an error if not.
87
97
88
-
###Rx Utils
98
+
## Rx Utils
89
99
Mini includes some utility extensions over RxJava 2.0 to make easier listen state changes over the `Stores`.
90
100
91
101
-`mapNotNull`: Will emit only not null values over the given `map` clause.
@@ -107,7 +117,7 @@ For example:
107
117
108
118
If we continually listen the changes of a `Task` and we navigate to a specific screen when the `Task` becomes successful. The state will stay on SUCCESS and if we navigate back to the last screen we will be redirected again.
109
119
110
-
###Logging
120
+
## Logging
111
121
Mini includes a custom `LoggerInterceptor` to log any change in your `Store` states produced from an `Action`. This will allow you to keep track of your actions, changes and side-effects more easily.
112
122
To add the LoggerInterceptor to your application you just need to add a single instance of it to your `Dispatcher` after initialize it in your `Application` class or dependency injection code.
113
123
```kotlin
@@ -157,11 +167,72 @@ fun login_redirects_to_home_with_success_task() {
157
167
```
158
168
159
169
## Setting Up
160
-
161
170
### Import the library
162
171
163
-
🚧WIP🚧
172
+
Add the following dependencies to your main `build.gradle`:
173
+
```groovy
174
+
allprojects {
175
+
repositories {
176
+
maven { url "https://jitpack.io" }
177
+
}
178
+
}
179
+
```
164
180
165
-
### Setting up your App file
181
+
Add the following dependencies to your app's `build.gradle`:
You'll need to add the following snippet to your `Application`'s `onCreate` method. If you don't have it, then create it and reference it in your `AndroidManifest.xml` file:
206
+
207
+
```kotlin
208
+
val stores = listOf<Store<*>>(...) // Here you'll set-up you store list, you can retrieve it using your preferred DI framework
209
+
val dispatcher =MiniGen.newDispatcher() // Create a new dispatcher
0 commit comments