@@ -24,6 +24,7 @@ var Events = {
2424 if ( plotObj . _ev instanceof EventEmitter ) return plotObj ;
2525
2626 var ev = new EventEmitter ( ) ;
27+ var internalEv = new EventEmitter ( ) ;
2728
2829 /*
2930 * Assign to plot._ev while we still live in a land
@@ -32,6 +33,16 @@ var Events = {
3233 */
3334 plotObj . _ev = ev ;
3435
36+ /*
37+ * Create a second event handler that will manage events *internally*.
38+ * This allows parts of plotly to respond to thing like relayout without
39+ * having to use the user-facing event handler. They cannot peacefully
40+ * coexist on the same handler because a user invoking
41+ * plotObj.removeAllListeners() would detach internal events, breaking
42+ * plotly.
43+ */
44+ plotObj . _internalEv = internalEv ;
45+
3546 /*
3647 * Assign bound methods from the ev to the plot object. These methods
3748 * will reference the 'this' of plot._ev even though they are methods
@@ -46,6 +57,15 @@ var Events = {
4657 plotObj . removeListener = ev . removeListener . bind ( ev ) ;
4758 plotObj . removeAllListeners = ev . removeAllListeners . bind ( ev ) ;
4859
60+ /*
61+ * Create funtions for managing internal events. These are *only* triggered
62+ * by the mirroring of external events via the emit function.
63+ */
64+ plotObj . _internalOn = internalEv . on . bind ( internalEv ) ;
65+ plotObj . _internalOnce = internalEv . once . bind ( internalEv ) ;
66+ plotObj . _removeInternalListener = internalEv . removeListener . bind ( internalEv ) ;
67+ plotObj . _removeAllInternalListeners = internalEv . removeAllListeners . bind ( internalEv ) ;
68+
4969 /*
5070 * We must wrap emit to continue to support JQuery events. The idea
5171 * is to check to see if the user is using JQuery events, if they are
@@ -58,6 +78,7 @@ var Events = {
5878 }
5979
6080 ev . emit ( event , data ) ;
81+ internalEv . emit ( event , data ) ;
6182 } ;
6283
6384 return plotObj ;
@@ -68,6 +89,10 @@ var Events = {
6889 * all handlers for a particular event and returns the return value
6990 * of the LAST handler. This function also triggers jQuery's
7091 * 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.
7196 */
7297 triggerHandler : function ( plotObj , event , data ) {
7398 var jQueryHandlerValue ;
@@ -124,6 +149,13 @@ var Events = {
124149 delete plotObj . removeAllListeners ;
125150 delete plotObj . emit ;
126151
152+ delete plotObj . _ev ;
153+ delete plotObj . _internalEv ;
154+ delete plotObj . _internalOn ;
155+ delete plotObj . _internalOnce ;
156+ delete plotObj . _removeInternalListener ;
157+ delete plotObj . _removeAllInternalListeners ;
158+
127159 return plotObj ;
128160 }
129161
0 commit comments