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: docs/binding_and_lifecycle.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Binding
4
4
5
-
Connecting inputs and outputs sounds like a simple task. And indeed it is. But it can be even easier if you use [Binder](https://github.com/arkivanov/MVIKotlin/blob/master/mvikotlin/src/commonMain/kotlin/com/arkivanov/mvikotlin/core/binder/Binder.kt). It provides just two methods: `start()` and `stop()`. When you call `start()` it connects (subscribes) outputs with inputs. And when you call `stop()` it disconnects (unsubscribes).
5
+
Connecting inputs and outputs sounds like a simple task, and indeed it is. But it can be even easier if you use [Binder](https://github.com/arkivanov/MVIKotlin/blob/master/mvikotlin/src/commonMain/kotlin/com/arkivanov/mvikotlin/core/binder/Binder.kt). It provides just two methods: `start()` and `stop()`. When you call `start()` it connects (subscribes) outputs with inputs. And when you call `stop()` it disconnects (unsubscribes).
6
6
7
7
### Creating a Binder
8
8
@@ -74,14 +74,15 @@ Please note that you must dispose `Stores` at the end of life cycle. In this exa
74
74
75
75
## Lifecycle
76
76
77
-
MVIKotlin provides an abstraction over [Lifecycle](https://github.com/arkivanov/MVIKotlin/blob/master/mvikotlin/src/commonMain/kotlin/com/arkivanov/mvikotlin/core/lifecycle/Lifecycle.kt) states and events. Please take a look at the following diagram:
78
-

77
+
MVIKotlin uses [Essenty](https://github.com/arkivanov/Essenty) library (from the same author), which provides `Lifecycle` - a multiplatform abstraction for lifecycle states and events. The Essenty's `lifecycle` module is used as `api` dependency, so you don't need to explicitly add it to your project. Please familiarise yourself with Essenty library, especially with the `Lifecycle`.
79
78
80
-
You can subscribe to `Lifecycle` events and unsubscribe from it. You can convert the [AndroidX Lifecycle](https://developer.android.com/topic/libraries/architecture/lifecycle) to MVIKotlin `Lifecycle` using [asMviLifecycle()](https://github.com/arkivanov/MVIKotlin/blob/master/mvikotlin/src/androidMain/kotlin/com/arkivanov/mvikotlin/core/lifecycle/AndroidLifecycleExt.kt) extension function. Also there is [LifecycleRegistry](https://github.com/arkivanov/MVIKotlin/blob/master/mvikotlin/src/commonMain/kotlin/com/arkivanov/mvikotlin/core/lifecycle/LifecycleRegistry.kt) which implements both the `Lifecycle` and `Lifecycle.Callbacks` interfaces, so you can manually control it.
79
+
<imgsrc="media/lifecycle.jpg"width="512">
81
80
82
81
## Binder + Lifecycle
83
82
84
-
Work with the `Binder` can be simplified if you use the `Lifecycle`. Let's simplify our previous binding example::
83
+
Work with the `Binder` can be simplified if you use the `Lifecycle`. You need to add one of the extension modules in order to use `Binder` with `Lifecycle`, either `mvikotlin-extensions-reaktive` or `mvikotlin-extensions-coroutines`.
MVI stands for Model-View-Intent. It is an architectural pattern that utilizes unidirectional data flow. The data circulates between `Model` and `View` only in one direction - from `Model` to `View` and from `View` to `Model`.
8
8
9
-

9
+
<imgsrc="media/mvi.jpg"width="256">
10
10
11
11
### What is MVIKotlin
12
12
@@ -17,7 +17,7 @@ MVIKotlin does not bring or enforce any particular architecture. Its responsibil
17
17
18
18
- To provide a single source of truth for `State` (the scope is not defined, it can be a whole app, a screen, a feature, or a part of a feature);
19
19
- To provide an abstraction for UI with efficient updates (however this is not obligatory, you can use whatever you want);
20
-
- To provide lifecycleaware connections (binding) between inputs and outputs (again this is not obligatory in any way).
20
+
- To provide lifecycle-aware connections (binding) between inputs and outputs (again this is not obligatory in any way).
21
21
22
22
Everything else is out of scope of the library, there are no definitions for "screens", "features", "modules", etc. Also, no particular reactive framework is enforced/exposed. This gives a lot of flexibility:
23
23
@@ -32,12 +32,13 @@ You can find one of the architecture options in the [samples](https://github.com
32
32
There are two core components in MVIKotlin:
33
33
34
34
-`Store` - represents `Model` from MVI, this is the place for business logic
35
-
-`MviView` - represents `View` from MVI, the UI part
35
+
-`MviView` - represents `View` from MVI, the UI part, optional
36
36
37
37
### How the data flows
38
38
39
39
Please take a look at the following diagram:
40
-

40
+
41
+
<imgsrc="media/mvikotlin.jpg"width="384">
41
42
42
43
The `Store` produces a stream of `States` which is transformed to a stream of `View Models` by a `Mapper` function (f). The `View` renders `View Models` and produces a stream of `View Events` which is transformed to a stream of `Intents` by another `Mapper` function (f). This makes the `Store` and the `View` independent from each other. You can also combine multiple `States` (multiple `Stores`) into a single `View Model` (single `View`), or multiple `View Events` (multiple `Views`) into a single `Intent` (single `Store`). But if you have only one `Store` and only one `View` and you need simplicity then your `View` can directly render `States` and produce `Intents`.
43
44
@@ -51,7 +52,6 @@ The data flows between core components only on Main thread.
51
52
52
53
MVI loves reactivity, it's all about data streams and transformations. MVIKotlin is a reactive framework. But the main functionality of the framework does not depend on any such library. A tiny abstraction over Rx is used instead. Extensions for [Reaktive](https://github.com/badoo/Reaktive) and for [Coroutines](https://github.com/Kotlin/kotlinx.coroutines) libraries are provided as separate modules.
53
54
54
-
55
55
### Kotlin/Native
56
56
57
57
MVIKotlin is Kotlin/Native friendly and supports its tricky memory model (please read about Kotlin/Native [concurrency](https://kotlinlang.org/docs/reference/native/concurrency.html) and [immutability](https://kotlinlang.org/docs/reference/native/immutability.html) if you are unsure).
0 commit comments