-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare Circuit in a more DI framework consistent fashion (#1154)
* Prepare Circuit in a more DI framework consistent fashion * Restore fully drawn reporting * Remove unused imports --------- Co-authored-by: Ashley Davies <[email protected]>
- Loading branch information
Showing
20 changed files
with
155 additions
and
229 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
55 changes: 35 additions & 20 deletions
55
app-launcher/common/src/commonMain/kotlin/io/ashdavies/playground/CircuitConfig.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 |
---|---|---|
@@ -1,25 +1,40 @@ | ||
package io.ashdavies.playground | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import com.slack.circuit.foundation.Circuit | ||
import com.slack.circuit.runtime.presenter.presenterOf | ||
import io.ashdavies.common.PlaygroundDatabase | ||
import io.ashdavies.content.PlatformContext | ||
import io.ashdavies.dominion.dominionPresenterFactory | ||
import io.ashdavies.dominion.dominionUiFactory | ||
import io.ashdavies.routes.routePresenterFactory | ||
import io.ashdavies.routes.routeUiFactory | ||
import io.ashdavies.content.reportFullyDrawn | ||
import io.ashdavies.dominion.addDominionBoxSetDetailsPresenter | ||
import io.ashdavies.dominion.addDominionBoxSetDetailsUi | ||
import io.ashdavies.dominion.addDominionBoxSetListPresenter | ||
import io.ashdavies.dominion.addDominionBoxSetListUi | ||
import io.ashdavies.http.LocalHttpClient | ||
import io.ashdavies.routes.addRoutePresenter | ||
import io.ashdavies.routes.addRouteUi | ||
import io.ashdavies.sql.LocalTransacter | ||
import io.ktor.client.HttpClient | ||
|
||
public fun Circuit(context: PlatformContext): Circuit = Circuit.Builder() | ||
.addPresenterFactories(getPresenterFactories(context)) | ||
.addUiFactories(getUiFactories(context)) | ||
.build() | ||
|
||
private fun getPresenterFactories(context: PlatformContext) = listOf( | ||
dominionPresenterFactory(), | ||
launcherPresenterFactory(), | ||
routePresenterFactory(context), | ||
) | ||
|
||
private fun getUiFactories(context: PlatformContext) = listOf( | ||
dominionUiFactory(), | ||
launcherUiFactory(), | ||
routeUiFactory(context), | ||
) | ||
@Composable | ||
public fun rememberCircuit( | ||
platformContext: PlatformContext, | ||
playgroundDatabase: PlaygroundDatabase = LocalTransacter.current as PlaygroundDatabase, | ||
httpClient: HttpClient = LocalHttpClient.current, | ||
): Circuit = remember(platformContext) { | ||
Circuit.Builder() | ||
.addPresenter<LauncherScreen, LauncherScreen.State> { _, navigator, _ -> | ||
presenterOf { LauncherPresenter(navigator) } | ||
} | ||
.addDominionBoxSetListPresenter(playgroundDatabase, httpClient) | ||
.addDominionBoxSetDetailsPresenter(playgroundDatabase, httpClient) | ||
.addRoutePresenter(platformContext) | ||
.addUi<LauncherScreen, LauncherScreen.State> { state, modifier -> | ||
LauncherScreen(state, modifier, platformContext::reportFullyDrawn) | ||
} | ||
.addDominionBoxSetListUi() | ||
.addDominionBoxSetDetailsUi() | ||
.addRouteUi() | ||
.build() | ||
} |
18 changes: 0 additions & 18 deletions
18
app-launcher/common/src/commonMain/kotlin/io/ashdavies/playground/LauncherFactory.kt
This file was deleted.
Oops, something went wrong.
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
17 changes: 0 additions & 17 deletions
17
circuit-support/src/commonMain/kotlin/io/ashdavies/circuit/Presenter.kt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
circuit-support/src/commonMain/kotlin/io/ashdavies/circuit/Ui.kt
This file was deleted.
Oops, something went wrong.
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
31 changes: 31 additions & 0 deletions
31
conferences-app/src/commonMain/kotlin/io/ashdavies/party/coroutines/StableCoroutineScope.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,31 @@ | ||
package io.ashdavies.party.coroutines | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.RememberObserver | ||
import androidx.compose.runtime.Stable | ||
import com.slack.circuit.retained.rememberRetained | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.cancel | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
private const val COROUTINE_SCOPE = "COROUTINE_SCOPE" | ||
|
||
@Stable | ||
internal class StableCoroutineScope(scope: CoroutineScope) : CoroutineScope by scope | ||
|
||
@Composable | ||
internal fun rememberRetainedCoroutineScope( | ||
context: CoroutineContext = Dispatchers.Main.immediate, | ||
): StableCoroutineScope = rememberRetained(COROUTINE_SCOPE) { | ||
val coroutineScope = StableCoroutineScope(CoroutineScope(context + Job())) | ||
rememberObserver(coroutineScope::cancel) | ||
coroutineScope | ||
} | ||
|
||
private fun rememberObserver(onForgotten: () -> Unit) = object : RememberObserver { | ||
override fun onAbandoned() = onForgotten() | ||
override fun onForgotten() = onForgotten() | ||
override fun onRemembered() = Unit | ||
} |
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.