Rxswift: Remove .distinctUntilChanged() in UIControl.rx_value

Created on 18 Apr 2016  路  3Comments  路  Source: ReactiveX/RxSwift

_rx_value_ in extension UIControl (RxCocoa.UIControl+Rx.swift) shouldn't call _.distinctUntilChanged()_ since it manipulates the native event behavior of a UIControl. Imho it should be up to the developer to call _.distinctUntilChanged()_ or not.

E.g. the developer wants to limit the character input within a UITextField, _.distinctUntilChanged()_ will prevent the developer from manipulating the input from every second event if the second content is equal to the previous content because the second event won't be dispatched at all.

textField.rx_text
            .map { text in
                text = [remove special characters from 'text' and assign the result to 'text' again]
                return text
            }
            .bindTo(textField.rx_text)
            .addDisposableTo(disposeBag)
bug

Most helpful comment

Hi @RobinFalko ,

What a sense for timing :) You are correct. I've encountered similar issues yesterday, and already removed all distinctUntilChanged. I've pushed my changes to develop branch :)

https://github.com/ReactiveX/RxSwift/commit/72edf869a075b2d7f68dc2e82af3610de575bf40

Please let me know if you find some other places we should remove distinctUntilChanged from.

All 3 comments

Hi @RobinFalko ,

What a sense for timing :) You are correct. I've encountered similar issues yesterday, and already removed all distinctUntilChanged. I've pushed my changes to develop branch :)

https://github.com/ReactiveX/RxSwift/commit/72edf869a075b2d7f68dc2e82af3610de575bf40

Please let me know if you find some other places we should remove distinctUntilChanged from.

I've just encountered a similar problem about UISwitch.rx_value.
I tried to call an uialertview with an inputTextField when UISwitch.rx_value is changing, in order to confirm this user has correct password for this operation.
if not, I'll change mySwitch.on to original setting programmatically.
However, uialertview didn't appear next time because distinctUntilChanged have blocked it.
I even tried to emit a new rx_value signal to reseting the previous rx_value, but I can't send any rx_value signal programmatically.
I think the solution of this issue will solve my problem as well. thank you all.

This one is just released.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmial picture dmial  路  3Comments

gekitz picture gekitz  路  3Comments

gregpardo picture gregpardo  路  4Comments

trungp picture trungp  路  3Comments

trant picture trant  路  3Comments