Skip to content

Commit

Permalink
gather docs
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Dec 14, 2022
1 parent cb2aedf commit d26b291
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 96 deletions.
Binary file removed compose/docs/img/koin_main_logo.png
Binary file not shown.
Binary file removed compose/docs/img/sponsors/stream-logo-2x.png
Binary file not shown.
Binary file removed compose/docs/img/sponsors/stream-logo.png
Binary file not shown.
78 changes: 0 additions & 78 deletions compose/docs/reference/koin-android/compose.md

This file was deleted.

24 changes: 6 additions & 18 deletions docs/reference/koin-android/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ For a module that declares a 'MyViewModel' component:
```kotlin
module {
viewModel { MyViewModel() }
// or constructor DSL
viewModelOf(::MyViewModel)
}
```

Expand All @@ -58,30 +60,16 @@ We can get your instance like that:
```kotlin
@Composable
fun App() {
val vm = getViewModel<MyViewModel>()
val vm = koinViewModel<MyViewModel>()
}
```

You can specify the `owner` & `scope`:

```kotlin
inline fun <reified T : ViewModel> getViewModel(
qualifier: Qualifier? = null,
owner: ViewModelOwner = getComposeViewModelOwner(),
scope: Scope = GlobalContext.get().scopeRegistry.rootScope,
noinline parameters: ParametersDefinition? = null,
)
```

Where ViewModelOwner can be used to pass a StoreOwner (like navigation):
We can get your instance in function parameters:

```kotlin
@Composable
fun getComposeViewModelOwner(): ViewModelOwner {
return ViewModelOwner.from(
LocalViewModelStoreOwner.current!!,
LocalSavedStateRegistryOwner.current
)
fun App(vm : MyViewModel = koinViewModel()) {

}
```

Expand Down
File renamed without changes.
Binary file removed ktor/docs/img/koin_main_logo.png
Binary file not shown.

0 comments on commit d26b291

Please sign in to comment.