Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene Dohan committed May 5, 2024
1 parent d3affb8 commit 6be9367
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ inline fun <ParentValue, ChildValue> CSHasChangeValue<ParentValue>.action(
})
}

inline fun <ParentValue, ChildValue> CSHasChangeValue<ParentValue>.actionNullable(
crossinline child: (ParentValue) -> CSHasChangeValue<ChildValue>?,
inline fun <ParentValue, ChildValue> CSHasChangeValue<ParentValue>.action(
crossinline optionalChild: (ParentValue) -> CSHasChangeValue<ChildValue>?,
crossinline onChange: ((ChildValue?) -> Unit)
): CSRegistration {
var childRegistration: CSRegistration? = null
val parentRegistration = action { parentValue ->
childRegistration?.cancel()
childRegistration = child(parentValue)?.let {
childRegistration = optionalChild(parentValue)?.let {
it.action { childValue -> onChange(childValue) }
} ?: run { onChange(null); null }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ interface CSHasChangeValue<T> : CSValue<T>, CSHasChange<T> {
): CSHasChangeValue<ChildValue?> {
val event = event<ChildValue?>()
var value: ChildValue? = null
actionNullable(
child = { child(it) },
action(
optionalChild = { child(it) },
onChange = {
value = it
onChange?.invoke(value)
Expand Down

0 comments on commit 6be9367

Please sign in to comment.