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: README.md
+18-2Lines changed: 18 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -104,6 +104,12 @@ will handle the `clear()` call automatically.
104
104
105
105
```
106
106
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
+
107
113
If you want your component to survive configuration changes you have to handle it yourself or you can use
108
114
`ElmViewModel` and pass in your component:
109
115
@@ -138,7 +144,17 @@ class CounterActivity : AppCompatActivity() {
138
144
}
139
145
```
140
146
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.
0 commit comments