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

Remove static create methods and provide importable functions instead #3513

Closed
benlesh opened this issue Apr 2, 2018 · 2 comments
Closed

Comments

@benlesh
Copy link
Member

benlesh commented Apr 2, 2018

The static create methods were a good idea, but they suffer from a couple of issues:

  1. TypeScript has a hard time typing them because of how static inheritance works. For example Subject inherits from Observable and BehaviorSubject inherits from Subject... all of them have (or should have) wildly different signatures for create.
  2. Because of how inheritance works, poorly implemented subclasses (like BehaviorSubject suffer from bugs like BehaviorSubject created with "create" does not have getValue() method #1890.
  3. Subject.create doesn't even do what the rest of the create methods do (which is just proxy the constructor), instead it returns an AnonymousSubject, which is really just any old observer "glued" to any old observable to make a subject. So we might want to change that to createSubject or frankenSubject or glueSubject (okay, I'm kidding on the last two) (but the name AnonymousSubject sorta sucks too)

Proposed solution

Create functions that do the same work and export them separately:

import { observable, behaviorSubject, /* et al */ } from 'rxjs';

// usage would be

observable(subscriber => {
  subscriber.next('hello world');
  subscriber.complete();
});
@kwonoj
Copy link
Member

kwonoj commented Apr 2, 2018

if we're going to away from exposing creation method directly, what makes us prevent just let ppl use class ctor instead of exporting another function for creation?

@benlesh
Copy link
Member Author

benlesh commented Oct 2, 2019

I think this is a non-issue these days. Closing for now.

@benlesh benlesh closed this as completed Oct 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants