Skip to content

Commit

Permalink
Disconnect triggerHandler from internal events
Browse files Browse the repository at this point in the history
  • Loading branch information
rreusser committed Sep 14, 2016
1 parent 66346bc commit dc9f58d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
21 changes: 5 additions & 16 deletions src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ var Events = {
* all handlers for a particular event and returns the return value
* of the LAST handler. This function also triggers jQuery's
* triggerHandler for backwards compatibility.
*
* Note: triggerHandler has been recommended for deprecation in v2.0.0,
* so the additional behavior of triggerHandler triggering internal events
* is deliberate excluded in order to avoid reinforcing more usage.
*/
triggerHandler: function(plotObj, event, data) {
var i;
var jQueryHandlerValue;
var nodeEventHandlerValue;
/*
Expand Down Expand Up @@ -120,24 +123,10 @@ var Events = {
/*
* Call all the handlers except the last one.
*/
for(i = 0; i < handlers.length; i++) {
for(var i = 0; i < handlers.length; i++) {
handlers[i](data);
}

/* Do the same as for external-facing events, except trigger the same
* events on the internal handlers. This does *not* affect the return
* value. It simply mirrors triggers internally so that there's no
* conflict with external user-defined events when plotly manages
* events internally.
*/
var internalHandlers = plotObj._internalEv._events[event];
if(internalHandlers) {
if(typeof internalHandlers === 'function') internalHandlers = [internalHandlers];
for(i = 0; i < internalHandlers.length; i++) {
internalHandlers[i](data);
}
}

/*
* Now call the final handler and collect its value
*/
Expand Down
4 changes: 2 additions & 2 deletions test/jasmine/tests/events_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Events', function() {
expect(result).toBe('pong');
});

it('mirrors events on the internal handler', function() {
it('does *not* mirror triggerHandler events on the internal handler', function() {
var eventBaton = 0;
var internalEventBaton = 0;

Expand All @@ -137,7 +137,7 @@ describe('Events', function() {
var result = Events.triggerHandler(plotDiv, 'ping');

expect(eventBaton).toBe(2);
expect(internalEventBaton).toBe(1);
expect(internalEventBaton).toBe(0);
expect(result).toBe('pong');
});

Expand Down

0 comments on commit dc9f58d

Please sign in to comment.