Skip to content

Commit dc9f58d

Browse files
committed
Disconnect triggerHandler from internal events
1 parent 66346bc commit dc9f58d

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

src/lib/events.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ var Events = {
8989
* all handlers for a particular event and returns the return value
9090
* of the LAST handler. This function also triggers jQuery's
9191
* triggerHandler for backwards compatibility.
92+
*
93+
* Note: triggerHandler has been recommended for deprecation in v2.0.0,
94+
* so the additional behavior of triggerHandler triggering internal events
95+
* is deliberate excluded in order to avoid reinforcing more usage.
9296
*/
9397
triggerHandler: function(plotObj, event, data) {
94-
var i;
9598
var jQueryHandlerValue;
9699
var nodeEventHandlerValue;
97100
/*
@@ -120,24 +123,10 @@ var Events = {
120123
/*
121124
* Call all the handlers except the last one.
122125
*/
123-
for(i = 0; i < handlers.length; i++) {
126+
for(var i = 0; i < handlers.length; i++) {
124127
handlers[i](data);
125128
}
126129

127-
/* Do the same as for external-facing events, except trigger the same
128-
* events on the internal handlers. This does *not* affect the return
129-
* value. It simply mirrors triggers internally so that there's no
130-
* conflict with external user-defined events when plotly manages
131-
* events internally.
132-
*/
133-
var internalHandlers = plotObj._internalEv._events[event];
134-
if(internalHandlers) {
135-
if(typeof internalHandlers === 'function') internalHandlers = [internalHandlers];
136-
for(i = 0; i < internalHandlers.length; i++) {
137-
internalHandlers[i](data);
138-
}
139-
}
140-
141130
/*
142131
* Now call the final handler and collect its value
143132
*/

test/jasmine/tests/events_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('Events', function() {
113113
expect(result).toBe('pong');
114114
});
115115

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

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

139139
expect(eventBaton).toBe(2);
140-
expect(internalEventBaton).toBe(1);
140+
expect(internalEventBaton).toBe(0);
141141
expect(result).toBe('pong');
142142
});
143143

0 commit comments

Comments
 (0)