diff --git a/convention-plugins/src/main/kotlin/root.publication.gradle.kts b/convention-plugins/src/main/kotlin/root.publication.gradle.kts index 8391a14..6be6463 100644 --- a/convention-plugins/src/main/kotlin/root.publication.gradle.kts +++ b/convention-plugins/src/main/kotlin/root.publication.gradle.kts @@ -3,7 +3,7 @@ plugins { } object Conf { const val GROUP = "net.kigawa" - const val VERSION = "3.2.0" + const val VERSION = "3.3.0" } group = Conf.GROUP @@ -18,6 +18,5 @@ nexusPublishing { // https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh repositories { sonatype() - } } diff --git a/hakate/src/commonMain/kotlin/net/kigawa/hakate/api/state/StateDispatcher.kt b/hakate/src/commonMain/kotlin/net/kigawa/hakate/api/state/StateDispatcher.kt index 92971cd..8d6f8e6 100644 --- a/hakate/src/commonMain/kotlin/net/kigawa/hakate/api/state/StateDispatcher.kt +++ b/hakate/src/commonMain/kotlin/net/kigawa/hakate/api/state/StateDispatcher.kt @@ -7,4 +7,5 @@ interface StateDispatcher { fun newState(): MutableState = newState(null) fun currentValue(state: State): T fun useState(block: suspend StateContext.() -> T): Job + fun newStateContext(): StateContext } \ No newline at end of file diff --git a/hakate/src/commonMain/kotlin/net/kigawa/hakate/impl/dispatcher/StateDispatcherImpl.kt b/hakate/src/commonMain/kotlin/net/kigawa/hakate/impl/dispatcher/StateDispatcherImpl.kt index 70f738e..608ba19 100644 --- a/hakate/src/commonMain/kotlin/net/kigawa/hakate/impl/dispatcher/StateDispatcherImpl.kt +++ b/hakate/src/commonMain/kotlin/net/kigawa/hakate/impl/dispatcher/StateDispatcherImpl.kt @@ -13,7 +13,7 @@ class StateDispatcherImpl( private val coroutineScope: CoroutineScope, ) : StateDispatcher { override fun newState(defaultValue: T): MutableState { - return StateImpl(defaultValue, StateContextImpl(this@StateDispatcherImpl, coroutineScope)) + return StateImpl(defaultValue, newStateContext()) } override fun currentValue(state: State): T { @@ -21,6 +21,10 @@ class StateDispatcherImpl( } override fun useState(block: suspend StateContext.() -> T): Job { - return StateContextImpl(this@StateDispatcherImpl, coroutineScope).dispatch { block() } + return newStateContext().dispatch { block() } + } + + override fun newStateContext(): StateContext { + return StateContextImpl(this@StateDispatcherImpl, coroutineScope) } } \ No newline at end of file