Skip to content

Remove static create methods and provide importable functions instead #3513

@benlesh

Description

@benlesh

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();
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions