Skip to content

Commit 8dc0b7b

Browse files
committed
feat: Update README with new API design
1 parent d11abf7 commit 8dc0b7b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Vector is based primarily around three classes: `VectorViewModel`, `VectorState`
1717

1818
The Vector ViewModel class is the heart of any screen built with Vector. It is an abstract class extending the Android Architecture Components ViewModel class, and therefore survives configuration changes. It is generic on a class implementing the `VectorState` interface. It is also the only class which can mutate state.
1919

20-
It exposes the current state through a `LiveData` object.
20+
It exposes the current state through a `Kotlin Flow`.
2121

2222
* **VectorState**
2323

@@ -53,11 +53,15 @@ class MyFragment: VectorFragment() {
5353

5454
override fun onActivityCreated(savedInstanceState: Bundle?) {
5555
super.onActivityCreated(savedInstanceState)
56-
56+
fragmentScope.launch {
57+
myViewModel.state.collect { state ->
58+
renderState(state, this@MyFragment::renderer)
59+
}
60+
}
5761
myViewModel.state.observe(viewLifecycleOwner, Observer { renderState() })
5862
}
5963

60-
override fun renderState = withState(myViewModel) { state ->
64+
override fun renderer(state: MyState) {
6165
messageTextView.text = state.message
6266
}
6367
}
@@ -82,10 +86,10 @@ class MyViewModel(initState: MyState): VectorViewModel<MyState>(initState) {
8286
}
8387
```
8488

85-
When the `setState()` function is given a state reducer, it internally enqueues it to a Kotlin `Channel`. The reducers passed to this channel are internally processed on a single background thread to avoid race conditions.
89+
When the `setState()` function is given a state reducer, it internally enqueues it to a Kotlin `Actor`. The reducers passed to this actor are processed sequentially to avoid race conditions.
8690

8791
### Projects using Vector
88-
* You can find a sample app along with the library in this repository.
92+
* You can find a [sample app](https://github.com/haroldadmin/Vector/tree/master/sampleapp) along with the library in this repository.
8993
* [MoonShot](https://www.github.com/haroldadmin/MoonShot) is another project of mine. It's an app to help you keep up with SpaceX launches, and is built with Vector.
9094

9195
If you would like your project using Vector to be featured here, please open an Issue on the repository. I shall take a look at it and add your project to the list.

0 commit comments

Comments
 (0)