Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic knit setup #48

Merged
merged 1 commit into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

___

Tangle creates [Dagger] bindings for Android classes using the [Anvil] Kotlin compiler plugin.
This is meant to be an alternative to [Hilt], for those who'd prefer to enjoy the faster compilation
and better flexibility of Anvil.
Tangle creates [Dagger] bindings for Android classes using the [Anvil] Kotlin compiler plugin. This
is meant to be an alternative to [Hilt], for those who'd prefer to enjoy the faster compilation and
better flexibility of Anvil.

Since Tangle is an extension upon Anvil, its code generation will be applied to **Kotlin** files only.
Since Tangle is an extension upon Anvil, its code generation will be applied to **Kotlin** files
only.

``` Kotlin
@ContributesViewModel(AppScope::class)
Expand Down Expand Up @@ -38,7 +39,6 @@ ____

<!--- END -->


## Config

The `TangleComponents` holder needs to be initialized with an application-scoped Dagger Component in
Expand Down Expand Up @@ -127,23 +127,24 @@ dependencies {
}
```


## SavedStateHandle injection

Tangle supports injecting [SavedStateHandle] into ViewModel constructors,
where the `SavedStateHandle` is provided by the ViewModel's owning `Fragment`/`Activity`/`NavBackStackEntry`.
Tangle supports injecting [SavedStateHandle] into ViewModel constructors, where
the `SavedStateHandle` is provided by the ViewModel's owning `Fragment`/`Activity`
/`NavBackStackEntry`.

In addition to or in lieu of `SavedStateHandle`, Tangle can automatically extract arguments
from the `SavedStateHandle` and inject them into the constructor,
through use of the `FromSavedStateHandle` annotation.
In addition to or in lieu of `SavedStateHandle`, Tangle can automatically extract arguments from
the `SavedStateHandle` and inject them into the constructor, through use of
the `FromSavedStateHandle` annotation.

If the constructor argument's type is not nullable, then Tangle will assert that the argument
is in the bundle while creating the ViewModel.
If the constructor argument's type is not nullable, then Tangle will assert that the argument is in
the bundle while creating the ViewModel.

If the argument is marked as nullable,
then Tangle will gracefully handle a missing argument and just inject `null`.
If the argument is marked as nullable, then Tangle will gracefully handle a missing argument and
just inject `null`.

Given this code:

``` Kotlin
@ContributesViewModel(AppScope::class)
class MyViewModel @VMInject constructor(
Expand All @@ -153,7 +154,9 @@ class MyViewModel @VMInject constructor(
val addressOrNull: String?
) : ViewModel()
```

Tangle will generate this Provider:

``` Kotlin
public class MyViewModel_Provider @Inject constructor(
private val savedStateHandle: Provider<SavedStateHandle>
Expand All @@ -170,7 +173,6 @@ public class MyViewModel_Provider @Inject constructor(
}
```


## Compose support

Tangle supports ViewModel "injection" in composables in a manner very similar to Hilt's
Expand Down Expand Up @@ -201,7 +203,11 @@ See the License for the specific language governing permissions and
limitations under the License.
```

[Anvil]:https://github.com/square/anvil
[Dagger]:https://dagger.dev
[Hilt]:https://dagger.dev/hilt/view-model.html
[SavedStateHandle]:https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate

[Anvil]: https://github.com/square/anvil

[Dagger]: https://dagger.dev

[Hilt]: https://dagger.dev/hilt/view-model.html

[SavedStateHandle]: https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate
31 changes: 31 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,34 @@ subprojects {
}
}
}

apply(plugin = "kotlinx-knit")

extensions.configure<kotlinx.knit.KnitPluginExtension> {

rootDir = rootProject.rootDir

files = fileTree(project.rootDir) {
include(
"**/*.md",
"**/*.kt",
"**/*.kts"
)
exclude(
"**/node_modules/**",
"**/build/**",
"**/.gradle/**"
)
}

moduleRoots = listOf(".")

moduleDocs = "build/dokka"
moduleMarkers = listOf("build.gradle", "build.gradle.kts")
siteRoot = "https://rbusarow.github.io/Tangle/api"
}

// Build API docs for all modules with dokka before running Knit
tasks.withType<kotlinx.knit.KnitTask>().configureEach {
dependsOn(tasks.findByName("dokkaHtmlMultiModule"))
}