Skip to content

Commit 92f4485

Browse files
committed
add Events.purge method,
- which all event method from the plot object
1 parent fa8b92d commit 92f4485

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/lib/events.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,19 @@ var Events = {
114114
*/
115115
return jQueryHandlerValue !== undefined ? jQueryHandlerValue :
116116
nodeEventHandlerValue;
117+
},
118+
119+
purge: function(plotObj) {
120+
delete plotObj._ev;
121+
delete plotObj.on;
122+
delete plotObj.once;
123+
delete plotObj.removeListener;
124+
delete plotObj.removeAllListeners;
125+
delete plotObj.emit;
126+
127+
return plotObj;
117128
}
129+
118130
};
119131

120132
module.exports = Events;

src/plot_api/plot_api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,9 @@ Plotly.purge = function purge(gd) {
24122412
// purge properties
24132413
Plots.purge(gd);
24142414

2415+
// purge event emitter methods
2416+
Events.purge(gd);
2417+
24152418
// remove plot container
24162419
if(fullLayout._container) fullLayout._container.remove();
24172420

test/jasmine/tests/events_test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,15 @@ describe('Events', function() {
181181
expect(eventBaton).toBe(3);
182182
expect(result).toBe('pong');
183183
});
184+
});
184185

186+
describe('purge', function() {
187+
it('should remove all method from the plotObj', function() {
188+
Events.init(plotObj);
189+
Events.purge(plotObj);
185190

191+
expect(plotObj).toEqual({});
192+
});
186193
});
187194

188195
});

0 commit comments

Comments
 (0)