-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* kdoc WIP * misc kdoc progress * Update build.gradle.kts * Update TangleGraph.kt * Update tangle.kt Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
dfbda73
commit 1402de3
Showing
15 changed files
with
269 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2021 Rick Busarow | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
androidLibrary | ||
kotlin("kapt") | ||
id("com.squareup.anvil") | ||
} | ||
|
||
dependencies { | ||
|
||
anvil(projects.tangleViewmodelCompiler) | ||
|
||
kaptTest(libs.google.dagger.compiler) | ||
|
||
testImplementation(libs.google.dagger.api) | ||
testImplementation(libs.junit.vintage) | ||
testImplementation(libs.kotest.assertions) | ||
testImplementation(libs.kotest.properties) | ||
testImplementation(libs.kotest.runner) | ||
testImplementation(libs.kotlinx.coroutines.core) | ||
testImplementation(libs.kotlinx.coroutines.test) | ||
testImplementation(libs.robolectric) | ||
testImplementation(projects.tangleApi) | ||
testImplementation(projects.tangleViewmodelApi) | ||
} |
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,16 @@ | ||
<!-- | ||
~ Copyright (C) 2021 Rick Busarow | ||
~ 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. | ||
--> | ||
|
||
<manifest package="tangle.viewmodel.api.samples"/> |
21 changes: 21 additions & 0 deletions
21
tangle-viewmodel-api/samples/src/test/java/samples/TangleFragmentDelegateSample.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,21 @@ | ||
package samples | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.ViewModel | ||
import tangle.viewmodel.ContributesViewModel | ||
import tangle.viewmodel.VMInject | ||
import tangle.viewmodel.tangle | ||
|
||
public class TangleFragmentDelegateSample { | ||
|
||
@Sample | ||
public fun byTangleSample() { | ||
class MyFragment : Fragment() { | ||
|
||
val viewModel: MyViewModel by tangle() | ||
} | ||
} | ||
} | ||
|
||
@ContributesViewModel(Unit::class) | ||
public class MyViewModel @VMInject constructor() : ViewModel() |
48 changes: 48 additions & 0 deletions
48
tangle-viewmodel-api/samples/src/test/java/samples/TangleGraphSample.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,48 @@ | ||
/* | ||
* Copyright (C) 2021 Rick Busarow | ||
* 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 samples | ||
|
||
import android.app.Application | ||
import dagger.BindsInstance | ||
import dagger.Component | ||
import tangle.viewmodel.TangleGraph | ||
|
||
public class TangleGraphSample { | ||
|
||
@Sample | ||
public fun initializeTangleGraph() { | ||
class MyApplication : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
val appComponent = DaggerMyAppComponent.factory() | ||
.create(this) | ||
|
||
TangleGraph.init(appComponent) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Component | ||
public interface MyAppComponent { | ||
@Component.Factory | ||
public interface Factory { | ||
|
||
public fun create(@BindsInstance application: Application): MyAppComponent | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tangle-viewmodel-api/samples/src/test/java/samples/_utils.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,27 @@ | ||
/* | ||
* Copyright (C) 2021 Rick Busarow | ||
* 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. | ||
*/ | ||
|
||
@file:Suppress("EXPERIMENTAL_API_USAGE") | ||
|
||
package samples | ||
|
||
import io.kotest.matchers.shouldBe | ||
import org.junit.Test | ||
|
||
public typealias Sample = Test | ||
|
||
public infix fun Any?.shouldPrint( | ||
expected: String | ||
): Unit = toString() shouldBe expected |
21 changes: 0 additions & 21 deletions
21
tangle-viewmodel-api/src/main/java/tangle/viewmodel/TangleComponents.kt
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
tangle-viewmodel-api/src/main/java/tangle/viewmodel/TangleGraph.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,45 @@ | ||
package tangle.viewmodel | ||
|
||
import tangle.inject.InternalTangleApi | ||
|
||
/** | ||
* Holds a reference to the application's Dagger graph, | ||
* so that it can be accessed by [TangleViewModelFactory]. | ||
* | ||
* This should be initialized as soon as possible after initializing the AppComponent. | ||
* | ||
* @sample samples.TangleGraphSample.initializeTangleGraph | ||
* @since 0.10.0 | ||
*/ | ||
public object TangleGraph { | ||
|
||
@PublishedApi | ||
@Suppress("ObjectPropertyNaming") | ||
internal val _components: MutableSet<Any> = mutableSetOf() | ||
|
||
/** | ||
* Sets a reference to the application's Dagger graph, | ||
* so that it can be accessed by [TangleViewModelFactory]. | ||
* | ||
* This should be initialized as soon as possible after initializing the AppComponent. | ||
* | ||
* @sample samples.TangleGraphSample.initializeTangleGraph | ||
* @param component the application-scoped Dagger component | ||
* @since 0.10.0 | ||
*/ | ||
public fun init(component: Any) { | ||
_components.add(component) | ||
} | ||
|
||
/** | ||
* Used to retrieve a Component of a given type. | ||
* | ||
* This is an internal Tangle API and may change at any time. | ||
* | ||
* @since 0.10.0 | ||
*/ | ||
@InternalTangleApi | ||
public inline fun <reified T> get(): T = _components | ||
.filterIsInstance<T>() | ||
.single() | ||
} |
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
22 changes: 22 additions & 0 deletions
22
tangle-viewmodel-api/src/main/java/tangle/viewmodel/TangleViewModelProviderMap.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
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
Oops, something went wrong.