Skip to content

Mirror events on an internal event handler #941

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

Merged
merged 3 commits into from
Sep 14, 2016
Merged

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Sep 14, 2016

Problem: Currently it is the responsibility of the item triggering an event to iterate over all controls and update them. This seems like a rather unmaintainable and tightly coupled pattern.

Solution: This PR creates a second event handler which receives a copy of all events emitted on the the regular event handler. It does this so that internal parts of plotly can respond to events without adding events onto the user-facing event handler—which would otherwise break plotly if the user ever executed plotObj.removeAllListeners().

Note that it mirrors the events so that it's not necessary to emit two copies of every event.

This could otherwise be achieved with a flag that differentiates internal vs external event handlers (so that removeAllListeners would not break things), but that would be significantly more invasive.

Possible caveat: Plotly is designed from the ground up to wipe things out and start over. This PR should be usable when refactoring controls, but we may need to add an extra cleanup phase that detaches events.

@rreusser rreusser force-pushed the internal-event-handler branch from a1a4c35 to edae9fc Compare September 14, 2016 20:25
* conflict with external user-defined events when plotly manages
* events internally.
*/
var internalHandlers = plotObj._internalEv._events[event];
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we ever need to call Events.triggerHandler on internal events?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps not. I didn't fully understand the use-case of this. It appeared that it was for backward compatibility with earlier jquery-based events, but yeah, perhaps not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's the only reason (that I can think of) why we still have that trigger event block: https://plot.ly/javascript/hover-events/#triggering-hover-events

I'd vote for dropping it in v2.0.0 (cc @alexcjohnson)

So, I'd vote for not adding support for triggerHandlers for internal events?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More specifically, It appear to me that triggerHandler was just a more jquery-like version of emit, but I could be wrong. If there's no use-case for it, I'm glad to remove. I have no preference of particular knowledge here, so I'll defer to you on this one.

Copy link
Contributor

@etpinard etpinard Sep 14, 2016

Choose a reason for hiding this comment

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

TODO

  • Let's remove this block
  • add comment on non-internal triggerHandler block mentioning that internal events don't support triggerHandler.

Copy link
Collaborator

@alexcjohnson alexcjohnson Sep 14, 2016

Choose a reason for hiding this comment

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

I'd vote for dropping it in v2.0.0

👍
In case there are people using it in the wild, it would be great if our v2 release notes could describe (or link to a description of) how to convert to the new form.

@etpinard
Copy link
Contributor

I really like this idea. @rreusser 👍

@rreusser
Copy link
Contributor Author

rreusser commented Sep 14, 2016

@etpinard I should add that I deliberately omitted a convenience function to trigger events on the internal handler (though you can still do that pretty trivially with gd._internalEv.emit). The idea is that the internal and external event handlers share the same events and really just exist to segregate the handlers.

@etpinard
Copy link
Contributor

I should add that I deliberate omitted a convenience function to trigger events on the internal handler

Yeah, that would be great.

@rreusser
Copy link
Contributor Author

No rush @etpinard but can you clarify/confirm whether changes are desired?

@rreusser
Copy link
Contributor Author

rreusser commented Sep 14, 2016

Ohh, sorry, I get it. Dropping triggerHandlers so don't bother adding more features that reinforce its usage. Okay.

@etpinard
Copy link
Contributor

Dropping triggerHandlers so don't bother adding more features that reinforce its usage

exactly 👍

@etpinard
Copy link
Contributor

Looks good 💃

@rreusser rreusser merged commit 920a333 into master Sep 14, 2016
@rreusser rreusser deleted the internal-event-handler branch September 14, 2016 21:40
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.

3 participants