-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
Events with more than one argument #84
Comments
@jfedyczak I don't think Server's are really a use case for xstream, as it's designed for (and only for) Cycle.js |
@TylorS Well, it is just an example of use with EventEmmiter event which is now supported by xstream as an extra... It seems unnatural to use another library for server side. Also I see it as a fix for somewhat incomplete implementation of |
xstream listener functions, just like ES Observable or RxJS, will always take just one argument. If there is an API that deviates from that, then we need to convert multiple args to an array or an object that collects them. I'd be happy to get a PR for this for |
It would help if the fromEvent had selector support like rxjs. Then one could map multiple arguments of the event to an object or just use the argument he needs or w/e. usecase:
|
I'm excited to take a stab at supporting these. @jfedyczak, I worked on the I can get a PR in for this, but if folks have concerns about a potentially breaking change for the extra and want that to be tackled in a particular way, let's discuss. My instincts are to move the (currently) third argument into an optional fourth argument, which would be a hash of options. Does this seem reasonable? // current
function fromEvent(element: EventTarget | EventEmitter,
eventName: string,
useCapture?: boolean = false): Stream<Event|any> {}
// new
// `EventOptions`, `SelectorFn` interfaces are glossed over here
function fromEvent(element: EventTarget | EventEmitter,
eventName: string,
selector?: SelectorFn,
options?: EventOptions): Stream<Event|any> {} edited to include an example of the updated signature |
I find |
Yeah, four parameters is a lot. I don't really like the method-on-options approach, but I can't express why. It just feels fishy to me. So, that signature (in my example) is what Rx implements. But Which way are folks leaning? |
most.js's way seems the best in my opinion. I don't think it'd be that hard to implement. |
Cool - I'll take that approach then. Thanks! |
If provided with an EventEmitter, `fromEvent` streams will emit an array of values when the EventEmitter provides listeners with multiple arguments. The previous implementation naively provided only the first argument, which made `fromEvent` incompatible with event interfaces that rely on providing multiple arguments to their listeners, such as Node's `http.Server`. An alternative solution involved providing selector support. This wasn't implemented for several reasons. 1. Modifying the function signature for the extra would be a breaking change. 2. An expanded function signature would become 'crowded', and one of the architectural goals of xstream is to keep interfaces as small as they need to be to achieve their goals. 3. Aggregating emitted events into an array is consistent with the implementation in Most.js, and achieves similar flexibility with Rx when providing a selector function to `.map()` on a result stream. `fromEvent` will now emit mixed-types. If consumers are not responsible for calling `.emit()` on the source emitter, they should implement appropriate guards to ensure they are dealing with an intended type. Should resolve staltz#84.
If provided with an EventEmitter, `fromEvent` streams will emit an array of values when the EventEmitter provides listeners with multiple arguments. The previous implementation naively provided only the first argument, which made `fromEvent` incompatible with event interfaces that rely on providing multiple arguments to their listeners, such as Node's `http.Server`. An alternative solution involved providing selector support. This wasn't implemented for several reasons. 1. Modifying the function signature for the extra would be a breaking change. 2. An expanded function signature would become 'crowded', and one of the architectural goals of xstream is to keep interfaces as small as they need to be to achieve their goals. 3. Aggregating emitted events into an array is consistent with the implementation in Most.js, and achieves similar flexibility with Rx when providing a selector function to `.map()` on a result stream. `fromEvent` will now emit mixed-types. If consumers are not responsible for calling `.emit()` on the source emitter, they should implement appropriate guards to ensure they are dealing with an intended type. Should resolve staltz#84.
If provided with an EventEmitter, `fromEvent` streams will emit an array of values when the EventEmitter provides listeners with multiple arguments. The previous implementation naively provided only the first argument, which made `fromEvent` incompatible with event interfaces that rely on providing multiple arguments to their listeners, such as Node's `http.Server`. An alternative solution involved providing selector support. This wasn't implemented for several reasons. 1. Modifying the function signature for the extra would be a breaking change. 2. An expanded function signature would become 'crowded', and one of the architectural goals of xstream is to keep interfaces as small as they need to be to achieve their goals. 3. Aggregating emitted events into an array is consistent with the implementation in Most.js, and achieves similar flexibility with Rx when providing a selector function to `.map()` on a result stream. `fromEvent` will now emit mixed-types. If consumers are not responsible for calling `.emit()` on the source emitter, they should implement appropriate guards to ensure they are dealing with an intended type. Should resolve #84. Was PR #89.
Done in v5.3.0 |
As per suggestion of @xtianjohns I'm creating new issue conected with this issue. There's a problem with emitting events with more than one argument as in:
Possible solution would be emitting an array with all the args or passing all the args...
The text was updated successfully, but these errors were encountered: