-
-
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
fromEvent on node.js events #65
Comments
As stated in docs, function fromNodeEvent(emitter, event) {
let callback;
return xs.create({
start(listener) {
callback = value => listener.next(value);
emitter.addListener(event, callback);
},
stop() {
emitter.removeListener(event, callback);
}
});
} |
Maybe such method should be added? It is present in |
I think we could do this, since fromEvent is an extra, and size is not a concern, but parity with RxJS and most.js is a benefit. |
Add support for stream generation from EventEmitters. fromEvent will accept as a first argument either a DOMElement or an EventEmitter. When providing fromEvent with an EventEmitter, the third argument is always ignored. Internally, include an additional Producer type within fromEvent to support type checking. Related to staltz#65.
PR #73. * Support EventEmitters in fromEvent extra Add support for stream generation from EventEmitters. fromEvent will accept as a first argument either a DOMElement or an EventEmitter. When providing fromEvent with an EventEmitter, the third argument is always ignored. Internally, include an additional Producer type within fromEvent to support type checking. Related to #65. * Revert indent change Revert indentation change to remain consistent with project style. * Refactor guards; Conform test and source style Introduce style changes to enforce project source consistency. Adjust type checking within the fromEvent function. Specifically, duck type the first argument rather than rely on `instanceof` or `typeof` guards when deciding which producer type to instantiate. * Remove whitespace to align with project style requirements. * Remove destructuring assignment in producer class methods. * Update documentation to include both uses of the extra. * Remove whitespaces and semicolons from example markdown. * Refactor producer instantiation guards to implement duck-typing rather than `instanceof`/`typeof` checking. * Remove unused import from tests * Reorder assertion equality arguments. * Rename parameter in fromEvent documentation (`eventType`>`eventName`) * Expand emitter guard Check for both `addListener` and `emit` methods on an element supplied to fromEvent. This ensures that the function will not attempt to invoke the `addListener` method on an xstream stream instance with incorrect arguments. Instead, this scenario will throw a TypeError: 'this.node.addEventListener is not a function'
Thank you for the fix, but I'm trying to test this and I believe 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... |
Yeah, it would have to be an array or an object. |
I sympathize with the use case there, @jfedyczak. I think implementations in other libraries handle this issue with selector support, which allows users to declare how to map the arguments from the emitter into the stream. I'd be happy to take a stab at that, but I think it deserves a separate issue and maybe a discussion about how that approach fits in with the larger goals of xstream. |
I'm trying to migrate from most.js. Is it possible to use
fromEvent
on node.js events? I'm trying to passEventEmitter
as a source but with no luck...The text was updated successfully, but these errors were encountered: