Skip to content

Commit bdb500c

Browse files
committed
Update readme with new stuff from version 0.5
1 parent dc4f17b commit bdb500c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ will handle the `clear()` call automatically.
104104

105105
```
106106

107+
You can go even further and use `createRuntimeFor(component)` helper method that also handles lifecycle for you.
108+
109+
```kotlin
110+
runtime = createRuntimeFor(CounterComponent())
111+
```
112+
107113
If you want your component to survive configuration changes you have to handle it yourself or you can use
108114
`ElmViewModel` and pass in your component:
109115

@@ -138,7 +144,17 @@ class CounterActivity : AppCompatActivity() {
138144
}
139145
```
140146

141-
You can check a complete counter sample in [samples][counter-sample]
147+
And because we want to make it even easier, we provide `getViewModelFor(component)` function which gives you the option not to define `ElmComponentViewModel`
148+
subclass and just ask for instance of `ElmComponentViewModel` wrapping given component.
149+
150+
```kotlin
151+
viewModel = getViewModelFor(CounterComponent())
152+
```
153+
154+
Internally it uses `ViewModelProviders.of()` so there is no magic and no surprise behaviour. `getViewModelFor(component)` is just a huge shortcut where otherwise you
155+
would have to implement your `ViewModelFactory` etc.
156+
157+
Check out [samples][samples] to explore even more.
142158

143159
### Commands and Subscriptions
144160

@@ -285,7 +301,7 @@ allprojects {
285301
And add the dependency:
286302
```groovy
287303
dependencies {
288-
implementation 'com.github.InventiDevelopment:Elmdroid:0.4'
304+
implementation 'com.github.InventiDevelopment:Elmdroid:0.5'
289305
}
290306
```
291307

sample/src/main/java/com/example/elmdroid/counter/CounterActivity.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@ package com.example.elmdroid.counter
33
import android.os.Bundle
44
import android.support.v7.app.AppCompatActivity
55
import com.example.elmdroid.R
6-
import cz.inventi.elmdroid.ComponentRuntime
76
import cz.inventi.elmdroid.createRuntimeFor
87
import kotlinx.android.synthetic.main.activity_counter.*
98
import net.semanticer.renderit.renderit
109

1110
class CounterActivity : AppCompatActivity() {
1211

13-
private lateinit var runtime: ComponentRuntime<CounterState, CounterMsg>
14-
1512
override fun onCreate(savedInstanceState: Bundle?) {
1613
super.onCreate(savedInstanceState)
1714
setContentView(R.layout.activity_counter)
1815
supportActionBar?.title = getString(R.string.basic_counter)
1916

20-
runtime = createRuntimeFor(CounterComponent())
17+
val runtime = createRuntimeFor(CounterComponent())
2118

2219
renderit(runtime.state()) { state ->
2320
state from { it.counter } into { counter.text = "$it" }

0 commit comments

Comments
 (0)