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

Adding operator attachEventWithElement #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

krakenfuss
Copy link
Contributor

What changed in this PR:

This PR adds the operator attachEventWIthElement which extends the already existing attachEvent operator by returning an observable that will contains the el reference where the eventHandler(s) are attached to.

@krakenfuss krakenfuss requested a review from pago June 24, 2019 13:07
Copy link
Contributor

@pago pago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% convinced that we should add this feature and would like to encourage thinking about an alternative such as opening up the possibility to have more than one ref per element.

import { combineRefs } from './combineRefs';
import { of } from 'rxjs';

export const attachEventWithElement = (...events) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the ergonomics of this operator. What I don't like is that it produces only a single stream for all of the registered events, forcing the user of the API to do the splitting manually. I have the feeling that it'd be more valuable if it returned one stream per defined event.

The other part of the question is whether we should add this at all. Its a userland solution for an underlying problem: You can only define a single ref per element. So if we find a way to add more than one ref, that might solve the problem already.

What do you think?

...eventsAndElement.map(([handler]) => handler)
);
const streams = eventsAndElement.map(([_, stream]) => stream);
return [refHandler, ...streams];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep this API design we could use streams[0], streams[1] here instead of the spread operator for more explicitness, smaller size and better performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for the other usages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants