Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +18,5 @@ nexusPublishing {
// https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
repositories {
sonatype()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ interface StateDispatcher {
fun <T> newState(): MutableState<T?> = newState(null)
fun <T> currentValue(state: State<T>): T
fun <T> useState(block: suspend StateContext.() -> T): Job
fun newStateContext(): StateContext
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ class StateDispatcherImpl(
private val coroutineScope: CoroutineScope,
) : StateDispatcher {
override fun <T> newState(defaultValue: T): MutableState<T> {
return StateImpl(defaultValue, StateContextImpl(this@StateDispatcherImpl, coroutineScope))
return StateImpl(defaultValue, newStateContext())
}

override fun <T> currentValue(state: State<T>): T {
return state.currentValue()
}

override fun <T> 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)
}
}