-
-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move package + dsl to allow viewModel definition from common source
- Loading branch information
1 parent
1f416bc
commit 854d9d7
Showing
8 changed files
with
540 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../koin-compose-viewmodel/src/commonMain/kotlin/org/koin/compose/viewmodel/dsl/ModuleExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2017-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.koin.compose.viewmodel.dsl | ||
|
||
import androidx.lifecycle.ViewModel | ||
import org.koin.core.definition.Definition | ||
import org.koin.core.definition.KoinDefinition | ||
import org.koin.core.module.Module | ||
import org.koin.core.qualifier.Qualifier | ||
|
||
//TODO Ported from Android side | ||
|
||
/** | ||
* ViewModel DSL Extension | ||
* Allow to declare a ViewModel - be later inject into Activity/Fragment with dedicated injector | ||
* | ||
* @author Arnaud Giuliani | ||
* | ||
* @param qualifier - definition qualifier | ||
* @param definition - allow definition override | ||
*/ | ||
inline fun <reified T : ViewModel> Module.viewModel( | ||
qualifier: Qualifier? = null, | ||
noinline definition: Definition<T> | ||
): KoinDefinition<T> { | ||
return factory(qualifier, definition) | ||
} |
38 changes: 38 additions & 0 deletions
38
...oin-compose-viewmodel/src/commonMain/kotlin/org/koin/compose/viewmodel/dsl/ScopeSetExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2017-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.koin.compose.viewmodel.dsl | ||
|
||
import androidx.lifecycle.ViewModel | ||
import org.koin.core.definition.Definition | ||
import org.koin.core.definition.KoinDefinition | ||
import org.koin.core.qualifier.Qualifier | ||
import org.koin.dsl.ScopeDSL | ||
|
||
/** | ||
* ViewModel DSL Extension | ||
* Allow to declare a ViewModel - be later inject into Activity/Fragment with dedicated injector | ||
* | ||
* @author Arnaud Giuliani | ||
* | ||
* @param qualifier - definition qualifier | ||
* @param definition - allow definition override | ||
*/ | ||
inline fun <reified T : ViewModel> ScopeDSL.viewModel( | ||
qualifier: Qualifier? = null, | ||
noinline definition: Definition<T> | ||
): KoinDefinition<T> { | ||
return factory(qualifier, definition) | ||
} |
224 changes: 224 additions & 0 deletions
224
...ompose-viewmodel/src/commonMain/kotlin/org/koin/compose/viewmodel/dsl/ScopeViewModelOf.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
/* | ||
* Copyright 2017-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.koin.compose.viewmodel.dsl | ||
|
||
import androidx.lifecycle.ViewModel | ||
import org.koin.core.annotation.KoinInternalApi | ||
import org.koin.core.definition.KoinDefinition | ||
import org.koin.core.module.dsl.DefinitionOptions | ||
import org.koin.core.module.dsl.new | ||
import org.koin.core.module.dsl.onOptions | ||
import org.koin.dsl.ScopeDSL | ||
|
||
/** | ||
* Declare a [ScopeDSL.viewModel] definition by resolving a constructor reference for the dependency. | ||
* The resolution is done at compile time by leveraging inline functions, no reflection is required. | ||
* | ||
* Example: | ||
* ``` | ||
* class MyViewModel : ViewModel() | ||
* | ||
* val myModule = module { | ||
* viewModelOf(::MyViewModel) | ||
* } | ||
* ``` | ||
* | ||
* @author Arnaud Giuliani | ||
* | ||
* @see new - function operator | ||
*/ | ||
|
||
inline fun <reified R : ViewModel> ScopeDSL.viewModelOf( | ||
crossinline constructor: () -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15, reified T16> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15, reified T16, reified T17> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15, reified T16, reified T17, reified T18> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15, reified T16, reified T17, reified T18, reified T19> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15, reified T16, reified T17, reified T18, reified T19, reified T20> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15, reified T16, reified T17, reified T18, reified T19, reified T20, reified T21> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) | ||
|
||
/** | ||
* @see viewModelOf | ||
*/ | ||
inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15, reified T16, reified T17, reified T18, reified T19, reified T20, reified T21, reified T22> ScopeDSL.viewModelOf( | ||
crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) -> R, | ||
noinline options: DefinitionOptions<R>? = null, | ||
): KoinDefinition<R> = viewModel { new(constructor) }.onOptions(options) |
Oops, something went wrong.