Rxjs: Subject.onNext not a function?

Created on 14 Dec 2015  路  13Comments  路  Source: ReactiveX/rxjs

I'm trying to get Rx Subjects to work following the RxJs docs. I'm using:

    import * as Rx from 'rxjs';
    var subject = new Rx.Subject();

    var subscription = subject.subscribe(
        function (x) {
            console.log('Next: ' + x);
        },
        function (err) {
            console.log('Error: ' + err);
        },
        function () {
            console.log('Completed');
        });

    subject.onNext(42);

But typescript tells me onNext is not a function, and if I force it with subject:any, the browser also tells me subject.onNext is not a function. Has the syntax changed?

Most helpful comment

Due to changes to accommodate the ES7 Observable spec, the API has changed for observables:

  • onNext -> next
  • onError -> error
  • onCompleted -> complete

I apologize for any confusion. We're working on a migration strategy (probably documentation) to land during the early stages of beta.

All 13 comments

Due to changes to accommodate the ES7 Observable spec, the API has changed for observables:

  • onNext -> next
  • onError -> error
  • onCompleted -> complete

I apologize for any confusion. We're working on a migration strategy (probably documentation) to land during the early stages of beta.

@thunderkid I'm going to close this one for now, as it's not a bug, and I _hope_ that my previous comment addresses your concerns.

Yes, that fixed it. Thanks. (btw I also noticed bufferWithTime doesn't seem to be there. I'm assuming it's been replaced with bufferTime.)

@thunderkid ... made this today... just for you: https://github.com/ReactiveX/RxJS/blob/master/MIGRATION.md

;)

It's a first go, so I expect it will be improved over the next month or so.

Brilliant, thanks. That'll remove a bit of guesswork. What's the eta of the 5.0 stable release?

I didn't realize https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/subjects/subject.md was a different thing than this one, the former has better Google-Fu.

Do you guys have a plan to give a hint on this document?
https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observer.md

@KunmyonChoi it already does. https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#observer-interface-changes-also-subjects . Please note given repo is for RxJS v4, does not contain v5 related changes.

oh shit I thought it was completed instead of complete, d'oh!

honestly, I think it would just be better to alias all of them with the old method names, dunno though

@ORESoftware that would really confuse newcomers. Starting working with a library that's a rewrite of an old one means not dealing with the old one at all. It's a complete rewrite, meaning it's not the same thing, meaning don't get their APIs mingled.
You should never take your knowledge for granted when you change major versions of a dependency.

@facelesspanda I am not a huge fan of aliasing, for many reasons, but in this case these methods will never change purpose, so onNext and next should do the same thing, it would be hugely convenient to just make onNext an alias of next, etc.

I don't see how it would be confusing to newcomers. All the documentation would point to the new methods, without any mention of the old. If someone forgets somewhere deep in a codebase to change onNext to next, then it will be simply convenient.

The change from onNext to next is not about breaking changes, it's about conforming to the ES7 spec, so it's really just not necessary to creating breaking changes when you're just renaming things. This is a case where aliasing would actually be just straight up a good thing.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterbakonyi05 picture peterbakonyi05  路  4Comments

jakovljevic-mladen picture jakovljevic-mladen  路  3Comments

dooreelko picture dooreelko  路  3Comments

matthewwithanm picture matthewwithanm  路  4Comments

benlesh picture benlesh  路  3Comments