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

implement RxJS-like BehaviorSubject #3

Closed
TylorS opened this issue Jan 19, 2016 · 5 comments
Closed

implement RxJS-like BehaviorSubject #3

TylorS opened this issue Jan 19, 2016 · 5 comments

Comments

@TylorS
Copy link
Member

TylorS commented Jan 19, 2016

Overview

Create a subject which behaves similarly to RxJS' BehaviorSubject

Motivation

Easier transitioning from RxJS to Most

@TylorS
Copy link
Member Author

TylorS commented Jan 19, 2016

@briancavalier @Frikki

Any suggestions on better naming?

TylorS added a commit that referenced this issue Jan 19, 2016
Update/Add dependencies on most and @most/hold
Add .next() .complete() methods to sink
Make stream 'hot'
Implement holdSubject
Implement behaviorSubject
Add tests for all of the above

Closes #1 #2 #3 #4
@axefrog
Copy link
Collaborator

axefrog commented Jan 21, 2016

If I were naming this I'd first try to describe its behaviour.

  • It always retains the latest value
  • It has an initial value to be used before anything has been emitted
  • It emits (replays?) the currently-retained value to new subscribers

How to say this in a class name? Ideas:

  • RetainedValueSubject
  • RetentionSubject
  • ValueRetentionSubject
  • LatestValueSubject
  • RecentValueSubject
  • ValueCaptureSubject
  • SingleCaptureSubject
  • CaptureLatestSubject
  • ReplayOnceSubject
  • SingularReplaySubject

@TylorS
Copy link
Member Author

TylorS commented Jan 22, 2016

I'm actually beginning to wonder if it would be a better to simply provide a single function with options instead. No real reason to continue to emulate RxJS.
e.g.

const {sink, stream} = subject() // regular subject 
const {sink, stream} = subject({replay: true}) // replaySubject
const {sink, stream} = subject({replay: true, initialValue: 1}) // behaviorSubject

@wishfoundry
Copy link

I would vote for something like

 const {sink, stream}  cacheLatest(size: number)
sink.add(initial)

supporting an initial value in the constructor seems superfluous at best, especially for buffers > 1.

@TylorS
Copy link
Member Author

TylorS commented Jan 22, 2016

I actually went ahead with a similar API to the above. If you check the README now, it has the API I decided upon. It does include the initial values.

@TylorS TylorS closed this as completed Jan 22, 2016
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

3 participants