Skip to content

Commit

Permalink
- fixed debounce property;
Browse files Browse the repository at this point in the history
  • Loading branch information
green-nick committed Jun 14, 2019
1 parent fce15fa commit a6b6354
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ internal class DebouncePropertyImpl<T>(
private val listeners = linkedSetOf<(T) -> Unit>()
private var previousUpdate: Cancellable? = null

override var value = initValue
@Volatile
private var _value = initValue

override var value
get() = _value
set(value) {
previousUpdate?.invoke()
previousUpdate = executor.invoke(delay) {
if (value == field) return@invoke
field = value
if (value == _value) return@invoke
_value = value
listeners.forEach { it(value) }
}
}
Expand All @@ -28,8 +32,8 @@ internal class DebouncePropertyImpl<T>(

override fun forceSet(value: T) {
previousUpdate?.invoke()
if (this.value == value) return
this.value = value
if (value == _value) return
_value = value
listeners.forEach { it(value) }
}

Expand Down

0 comments on commit a6b6354

Please sign in to comment.