Skip to content

Execute UseCase with context-param#178

Open
RudolfHladik wants to merge 6 commits into6.xfrom
feature/6.x-context-params
Open

Execute UseCase with context-param#178
RudolfHladik wants to merge 6 commits into6.xfrom
feature/6.x-context-params

Conversation

@RudolfHladik
Copy link
Copy Markdown
Contributor

No description provided.

import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart

context(coroutineScopeOwner: CoroutineScopeOwner)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change effectively requires users to enable the experimental -Xcontext-parameters compiler flag. Would it be possible to provide an alternative for users who prefer not to opt into this experimental feature just yet?

If I understand correctly, this feature enables us to implement the lifecycle-hook-related execution methods proposed in this PR. However, I don't see those implemented here — and I believe they should be included in Arkitekt for this feature to provide meaningful value (for both Essenty lifecycle and Android Lifecycle)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates coroutine use case execution helpers to Kotlin context-parameter-based APIs and updates build/lint configuration to support the change across modules.

Changes:

  • Introduces new execute/executeMapped APIs for UseCase/FlowUseCase implemented via Kotlin context parameters, and extracts related config into dedicated classes.
  • Enables -Xcontext-parameters in relevant Gradle modules and adjusts publishing/version wiring (including snapshot publishing workflow).
  • Applies broad formatting/cleanup updates and updates static analysis tooling/config (Detekt/Ktlint).

Reviewed changes

Copilot reviewed 55 out of 58 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
settings.gradle.kts Minor Gradle settings formatting (trailing comma).
example/src/test/java/app/futured/arkitekt/sample/ui/login/fragment/LoginViewModelTest.kt Whitespace cleanup in tests.
example/src/test/java/app/futured/arkitekt/sample/ui/form/FormViewModelTest.kt Test formatting/refactor for readability.
example/src/test/java/app/futured/arkitekt/sample/ui/detail/DetailViewModelTest.kt Removes unused import/whitespace cleanup.
example/src/test/java/app/futured/arkitekt/sample/ui/bottomsheet/ExampleViewModelTest.kt Whitespace cleanup in tests.
example/src/main/java/app/futured/arkitekt/sample/ui/main/MainActivity.kt Whitespace cleanup.
example/src/main/java/app/futured/arkitekt/sample/ui/login/LoginViewModel.kt Updates use case execution calls to new execute import.
example/src/main/java/app/futured/arkitekt/sample/ui/form/FormViewState.kt Removes trailing whitespace.
example/src/main/java/app/futured/arkitekt/sample/ui/form/FormViewModel.kt Imports new execute; minor formatting and cleanup.
example/src/main/java/app/futured/arkitekt/sample/ui/form/FormScreen.kt Removes unused LiveData observe import; formatting updates.
example/src/main/java/app/futured/arkitekt/sample/ui/detail/DetailViewModel.kt Removes unused import; formatting cleanup.
example/src/main/java/app/futured/arkitekt/sample/ui/detail/DetailScreen.kt Removes unused LiveData observe import.
example/src/main/java/app/futured/arkitekt/sample/ui/coroutinesresult/CoroutinesResultViewModel.kt Imports new execute API.
example/src/main/java/app/futured/arkitekt/sample/ui/coroutinesresult/CoroutinesResultScreen.kt Minor trailing-comma formatting.
example/src/main/java/app/futured/arkitekt/sample/ui/compose/ExampleApp.kt Whitespace cleanup.
example/src/main/java/app/futured/arkitekt/sample/ui/compose/BottomSheetSceneStrategy.kt Formatting changes; metadata helper adjusted.
example/src/main/java/app/futured/arkitekt/sample/ui/compose/BackStackNavigator.kt Formatting/spacing updates.
example/src/main/java/app/futured/arkitekt/sample/ui/bottomsheet/BottomSheetScreen.kt Compose modifier formatting updates.
example/src/main/java/app/futured/arkitekt/sample/injection/ApplicationComponent.kt Formatting updates; adds trailing commas.
example/src/main/java/app/futured/arkitekt/sample/App.kt Import ordering adjustment.
example/build.gradle.kts Enables -Xcontext-parameters for sample module compilation.
detekt.yml Reworks Detekt configuration for updated plugin/version.
decompose/src/commonMain/kotlin/app/futured/arkitekt/decompose/presentation/BaseComponent.kt Formatting/refactor for scope/flow helpers.
decompose/src/commonMain/kotlin/app/futured/arkitekt/decompose/navigation/ResultFlow.kt Formatting and serializer signature adjustments.
decompose/src/commonMain/kotlin/app/futured/arkitekt/decompose/ext/NavigationExt.kt Formatting; removes unused import.
decompose/src/commonMain/kotlin/app/futured/arkitekt/decompose/coroutines/ValueStateFlow.kt Adds opt-in annotation for inheritance API.
decompose/build.gradle.kts Publishing DSL formatting/trailing commas.
decompose-processor/src/jvmMain/kotlin/app/futured/arkitekt/factorygenerator/processor/PoetFactoryComponentGenerator.kt Minor formatting cleanup.
decompose-processor/build.gradle.kts Publishing DSL formatting/trailing commas.
decompose-annotation/src/commonMain/kotlin/app/futured/arkitekt/annotation/GenerateFactory.kt Formatting cleanup.
decompose-annotation/build.gradle.kts Publishing DSL formatting/trailing commas.
cr-usecases/src/commonMain/kotlin/app/futured/arkitekt/crusecases/UseCaseExecution.kt Adds new context-parameter execute API for UseCase.
cr-usecases/src/commonMain/kotlin/app/futured/arkitekt/crusecases/UseCaseConfig.kt Adds new config builder for UseCase.execute.
cr-usecases/src/commonMain/kotlin/app/futured/arkitekt/crusecases/FlowUseCaseExecution.kt Adds new context-parameter execute/executeMapped for FlowUseCase.
cr-usecases/src/commonMain/kotlin/app/futured/arkitekt/crusecases/FlowUseCaseConfig.kt Adds new config builder for FlowUseCase.execute*.
cr-usecases/src/commonMain/kotlin/app/futured/arkitekt/crusecases/FlowUseCase.kt Minor formatting cleanup.
cr-usecases/src/commonMain/kotlin/app/futured/arkitekt/crusecases/error/UseCaseErrorHandler.kt Minor formatting cleanup.
cr-usecases/src/commonMain/kotlin/app/futured/arkitekt/crusecases/CoroutineScopeOwner.kt Removes old embedded execute/config implementations; keeps scope utilities.
cr-usecases/build.gradle.kts Enables -Xcontext-parameters for the published use cases module.
cr-usecases-test/src/test/java/app/futured/arkitekt/crusecases/test/UseCaseTests.kt Updates tests to import new execute; formatting.
cr-usecases-test/src/test/java/app/futured/arkitekt/crusecases/test/TestCoroutineScopeOwner.kt Whitespace cleanup.
cr-usecases-test/src/test/java/app/futured/arkitekt/crusecases/test/FlowUseCaseTests.kt Updates tests to import new execute; formatting.
cr-usecases-test/src/main/java/app/futured/arkitekt/crusecases/test/UseCase.kt Formatting updates to helper APIs.
cr-usecases-test/build.gradle.kts Enables -Xcontext-parameters for test module compilation.
core/src/main/java/app/futured/arkitekt/core/BaseCoreViewModel.kt Minor formatting cleanup.
core/build.gradle.kts Publishing DSL formatting/trailing commas.
core-test/src/main/java/app/futured/arkitekt/core/viewmodel/ViewModelTest.kt Comment block formatting cleanup.
core-test/src/main/java/app/futured/arkitekt/core/view/InstantTaskExecutor.kt Refactors anonymous object formatting.
core-test/src/main/java/app/futured/arkitekt/core/test/internal/CoroutineScopeRule.kt Refactors apply formatting/expression body.
core-test/build.gradle.kts Publishing DSL formatting/trailing commas.
compose/src/main/java/app/futured/arkitekt/compose/BaseViewModel.kt Formatting updates for class declaration.
compose/build.gradle.kts Publishing DSL formatting/trailing commas; whitespace cleanup.
buildSrc/src/main/kotlin/Versions.kt Updates Detekt/Ktlint plugin versions.
build.gradle.kts Sets group/version in subprojects; updates Detekt DSL wiring.
arkitekt-lint/src/test/java/app/futured/arkitekt/lint/WrongEventNameDetectorTest.kt Refactors test code formatting.
arkitekt-lint/src/main/java/app/futured/arkitekt/lint/WrongEventNameDetector.kt Refactors detector formatting; minor API signature formatting.
arkitekt-lint/src/main/java/app/futured/arkitekt/lint/MvvmIssueRegistry.kt Formatting cleanup for issues list.
.github/workflows/publish_snapshot.yml Forces snapshot version via -PVERSION_NAME=... on publish.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +95 to +99
job = build(args)
.flowOn(coroutineScopeOwner.getWorkerDispatcher())
.onStart { flowUseCaseConfig.onStart() }
.mapNotNull { flowUseCaseConfig.onMap?.invoke(it) }
.onEach { flowUseCaseConfig.onNext(it) }
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executeMapped currently uses mapNotNull { flowUseCaseConfig.onMap?.invoke(it) }, which (a) silently drops all emissions if onMap isn't provided and (b) filters out nulls even when M is nullable. Consider requiring a non-null mapper for executeMapped (fail fast if missing) and using map (or only mapNotNull when M is non-null) to avoid unintended data loss.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +13
/**
* Asynchronously executes use case and saves it's Deferred. By default, all previous
* pending executions are canceled, this can be changed by the [config].
* This version is used for use cases without initial arguments.
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These KDoc sentences use "it's" where the possessive "its" is intended (e.g., "saves it's Deferred"). Please correct the grammar (and consider doing the same for the other occurrences in this file) to avoid confusing generated docs.

Copilot uses AI. Check for mistakes.
Comment on lines 67 to 69
@OptIn(ExperimentalMaterial3Api::class)
fun bottomSheet(
modalBottomSheetProperties: ModalBottomSheetProperties = ModalBottomSheetProperties()
): Map<String, Any> = mapOf(BOTTOM_SHEET_KEY to modalBottomSheetProperties)
fun bottomSheet(modalBottomSheetProperties: ModalBottomSheetProperties = ModalBottomSheetProperties()): Map<String, Any> = mapOf(BOTTOM_SHEET_KEY to modalBottomSheetProperties)

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bottomSheet(...) helper is currently written as a very long single line, which is likely to violate the configured max line length (140) and reduces readability. Please reformat it across multiple lines (and/or use an expression body wrapped for style compliance).

Copilot uses AI. Check for mistakes.
Comment on lines 6 to 9
/**
* The same as [StackNavigation.bringToFront] but does not recreate [configuration] if it's class is already on stack and
* the classes are not equal.
*/
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KDoc uses "it's" where the possessive "its" is intended ("if it's class is already on stack"). Please correct the grammar for clearer generated docs.

Copilot uses AI. Check for mistakes.
Comment on lines 11 to 16
/**
* This interface gives your class ability to execute [UseCase] and [FlowUseCase] Coroutine use cases.
* You may find handy to implement this interface in custom Presenters, ViewHolders etc.
* It is your responsibility to cancel [coroutineScope] when when all running tasks should be stopped.
* It is your responsibility to cancel [coroutineScope] when all running tasks should be stopped.
*/
interface CoroutineScopeOwner {
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execute/executeMapped were moved out of CoroutineScopeOwner into top-level functions using context parameters. This breaks existing in-repo call sites that relied on the old member-extension visibility (e.g. cr-usecases/src/jvmTest/.../CoroutineScopeOwnerTest.kt calls testUseCase.execute(...) without importing app.futured.arkitekt.crusecases.execute). Please update those usages or provide a backward-compatible shim/deprecation path to avoid build failures for current callers.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +26
compilerOptions {
freeCompilerArgs.add("-Xcontext-parameters")
}

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling -Xcontext-parameters for this published module means downstream consumers must also compile with the same (experimental) language feature to call APIs like UseCase.execute/FlowUseCase.execute. Please ensure this is explicitly documented as a breaking change (and consider offering non-context overloads or keeping the previous API as deprecated wrappers for smoother migration).

Suggested change
compilerOptions {
freeCompilerArgs.add("-Xcontext-parameters")
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants