-
Notifications
You must be signed in to change notification settings - Fork 3k
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
subscribe ignores second argument of event emitter #2431
Comments
That is how it works at the moment. You can get access to the second parameter by using project function: Rx.Observable.fromEvent(r, 'message', (channel, message) => [channel, message])
.subscribe(arr => {
console.log(arr[0]); // logs value of channel
console.log(arr[1]); // logs value of message
}); That being said it seems like a strong case to make |
Does redis have an |
yea it has,
`
sub.unsubscribe()
`
…On Wed, Mar 1, 2017 at 11:39 PM, Mateusz Podlasin ***@***.***> wrote:
Does redis have an off function for canceling subscriptions? How do you
stop listening to events?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2431 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHzqCEyEqj6pW3IYWbeXzoOjn2xhO0jbks5rhZEcgaJpZM4MPszu>
.
|
That's weird. If there is no |
We should probably update |
doesn't node rxjs/src/observable/FromEventObservable.ts Lines 10 to 13 in 7c41c08
|
@Podlas29 that does the job |
I'm not sure where this issue has landed - is there specific we need to resolve in this issue? |
It would probably be a more ergonomic API to default to an array if multiple args are provided, but it would also be a breaking change. At the same time, the workaround is very concise: Observable.fromEvent(r, 'message', Array.of)
.subscribe(([channel, message]) => {
// ...
}) |
or you could even create an object with lodash: Observable.from(r, 'message', partial(zipObject, ['channel', 'message']))
.subscribe(event => {
console.log(event.channel)
console.log(event.message)
}) |
zeromq for node alse use multipart replies which requires the above |
A simple use case about this issue and more about #3048 and PR #3049: const Observable = require('rxjs').Observable;
const Oboe = require('oboe');
// create oboe instance
const oboe = Oboe({
url: 'http://test-streaming.shengsoft.net',
method: 'GET'
});
// original usage of oboe node event
oboe.on('node', '!.*', function() {
console.log('from original oboe node event callback');
console.log(arguments); // here 3 arguments are passed in
console.log('');
});
// create another oboe instance
const oboe1 = Oboe({
url: 'http://test-streaming.shengsoft.net',
method: 'GET'
});
// use fromEventPattern to convert oboe event in Observable
const oboeObs = Observable.fromEventPattern((handler) => {
oboe1.on('node', '!.*', handler);
});
oboeObs.subscribe(function() {
console.log('from Observable handler');
console.log(arguments); // !!! only the first argument is passed in
console.log('');
}); In this simple use case Observable combines Oboe to consume a json-streaming server. The server returns only a part of a whole json object every second. Observable is introduced to process the data returned from the json-streaming server. But it got only the first argument while the original Oboe event passed 3 arguments in event handler. I have created a simple repo for you to retry what I mean. |
This is no longer an issue. |
I am using redis, which exposes the event emitter as follows with 2 arguments, without rxjs, i can get both arguments, however with rxjs, the second argument is missing.
is this supposed to be the case?
The text was updated successfully, but these errors were encountered: