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

Created the initial implementation of BehaviorSubject #256

Merged
merged 2 commits into from
May 7, 2013
Merged

Created the initial implementation of BehaviorSubject #256

merged 2 commits into from
May 7, 2013

Conversation

michaeldejong
Copy link
Contributor

I've been trying to implement the BehaviorSubject. Functionally it works as it should, but I'm not entirely happy with the static createWithDefaultValue(T) method. I can't create a static method create(T) because Subject extends Observable, which has a static create(Object) method. So to resolve that I had to give the static method in BehaviorSubject a different name.

Additionally I'm using an AtomicReference<T> in this static method to keep track of the last published value. I tried coming up with different solutions to push the last published value to the Observer when it's subscribing, but this seems to be the most clean solution.

If there's any feedback on either issue, please let me know.

@cloudbees-pull-request-builder

RxJava-pull-requests #119 SUCCESS
This pull request looks good

@benjchristensen
Copy link
Member

I agree it's obnoxious that the create method can't be used but I can't see a way around it when it's also an Observable.

If anyone else has other ideas on how to deal with this please suggest them otherwise I think the createWithDefaultValue(T) name is fine.

import rx.util.functions.Func1;

/**
* Subject that publishes the previous and all subsequent events to each {@link Observer} that subscribes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps replacing "previous" with "last" is clearer that this is not all previous events but only the most recent (last) event?

@cloudbees-pull-request-builder

RxJava-pull-requests #127 FAILURE
Looks like there's a problem with this pull request

@benjchristensen benjchristensen merged commit 24be900 into ReactiveX:master May 7, 2013
rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
- We don't need to add synchronization as the subjects can trust their source Observables to comply with the Rx contract.
- This optimization follows Rx Design Guidelines 6.8. Avoid serializing operators

This was discussed at ReactiveX#256
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

Successfully merging this pull request may close these issues.

3 participants