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

FromEventPattern does not conform to v4 #2088

Closed
mattpodwysocki opened this issue Oct 26, 2016 · 8 comments
Closed

FromEventPattern does not conform to v4 #2088

mattpodwysocki opened this issue Oct 26, 2016 · 8 comments

Comments

@mattpodwysocki
Copy link
Collaborator

The current implementation of fromEventPattern deviates from the current v4 implementation in several ways:

  • removeHandler is no longer optional
  • removeHandler does not get return value from addHandler

Is the intent here to follow this behavior, or deviate? If we are to deviate, then we must ask why the addHandler is addHandler: (handler: Function) => any instead of addHandler: (handler: Function) => void if we aren't returning anything, nor are we using the value produced from it.

RxJS version: v5 - current

Code to reproduce:

This is an example of using RxJS v4 with the addHandler returning a value, which would then be forwarded onto the remove handler.

Observable.fromEventPattern(
  (h) => { return elem.connect('data', h); },
  (_, r) => { r.disconnect(); }
);

Expected behavior:

The expected behavior would forward the return value from elem.connect('data', h) so that you could remove the handler from the value by calling disconnect.

Actual behavior:

Currently, RxJS v5 does not support doing anything with the addHandler despite its signature of allowing anything to be returned, hence why its signature of addHandler: (handler: Function) => any is confusing if nothing is ever done with the return value.

Additional information:

If this is indeed breaking change behavior, we should put that in the documentation and the reasons for this. The reason it was added originally was that some libraries instead pass a subscription like object to the user which you can later disconnect instead of the standard Subject/Observer pattern with add/remove handlers.

@benlesh
Copy link
Member

benlesh commented Oct 26, 2016

cc/ @trxcllnt who I believe is the original implementer. (this was added when RxJS was v 2 or 3 I think)

@trxcllnt
Copy link
Member

@Blesh I don't know how I got associated with implementing this, I've literally never touched this file. I'm halfway convinced you're messing with me :P

@mattpodwysocki I agree 100%, this should exactly match v4 behavior, something I would've done if I was the author of this version cough@Bleshcough

@jayphelps
Copy link
Member

I think @trxcllnt has been playing with git-blame-someone-else :trollface:

@trxcllnt
Copy link
Member

@jayphelps oh man good show. @Blesh #95

@paulpdaniels
Copy link
Contributor

I just ran into this while writing a wrapper for a Redux store. Fortunately in that case there was a simple work around of Observable.from(store).map(() => store.getState()), but still 💯

@benlesh
Copy link
Member

benlesh commented Oct 28, 2016

Oops, sorry @trxcllnt... for some reason I thought you had done the original work on this way back when we merged what you had done with what I had done when this was called "RxNext" or whatever. haha.

kwonoj added a commit to kwonoj/rxjs that referenced this issue Dec 28, 2016
kwonoj added a commit to kwonoj/rxjs that referenced this issue Jan 5, 2017
kwonoj added a commit to kwonoj/rxjs that referenced this issue Jan 15, 2017
@kwonoj
Copy link
Member

kwonoj commented Jan 16, 2017

Closing via #2224

@kwonoj kwonoj closed this as completed Jan 16, 2017
@lock
Copy link

lock bot commented Jun 6, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
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

6 participants