Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose view properties as subjects? #7

Closed
JakeWharton opened this issue Apr 2, 2015 · 2 comments
Closed

Expose view properties as subjects? #7

JakeWharton opened this issue Apr 2, 2015 · 2 comments

Comments

@JakeWharton
Copy link
Owner

Case study: The checked-ness of a CompoundButton.

We currently have two methods, one for reading and one for writing (RxCompoundButton.checkedChanges and RxCompoundButton.setChecked, respectively). These are two halves of the same coin which could potentially be more easily represented in a property-like fashion of Subject<Boolean, Boolean>. This would allow a single point of observation and subscription.

Currently there are two overloads for all property reads: one which observes a zero or one allocation value (e.g., the Boolean checked-ness in this example) and one which wraps all emissions in an event object (e.g., CheckedChangedEvent in this example). This would mean that we'd actually need two overloads for the property, Subject<Boolean, Boolean> and Subject<CheckedChangedEvent, Boolean> which is slightly unfortunate (but certainly no more than it currently is).

@dlew
Copy link
Contributor

dlew commented Apr 3, 2015

Would this mean that calling compoundButtonSubject.onNext(true) would cause the compound button to become checked?

If that's the case, then I am getting a nervous feeling about this because it's moving away from a functional approach and instead depends on side effects. With the two separated there is clearly a cause and an effect, with it combined then the effect could be a cause.

@JakeWharton
Copy link
Owner Author

Maybe we'll just do this internally with a dedicated type.

I don't necessarily want a side-effect-having Subject but rather want a single type with which I can both observe values and update values. This is especially desired in situations where I want to have a single type that I can inject to hide the underlying mechanism (views aren't a good example in this case. think: preferences).

I'm envisioning a simple Property<T> extends Observable<T> implements Action1<T> or a Property<T> which is a factory for Observable<T>s and Action1<T>s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants