Skip to content

Commit

Permalink
Close videojsGH-614: added dispose event. fixes videojs#613.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjem authored and heff committed Jul 18, 2013
1 parent 9d424c6 commit a449cb0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ vjs.Component = vjs.CoreObject.extend({
* Dispose of the component and all child components.
*/
vjs.Component.prototype.dispose = function(){
this.trigger('dispose');

// Dispose all children.
if (this.children_) {
for (var i = this.children_.length - 1; i >= 0; i--) {
Expand Down
4 changes: 3 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ vjs.Player = vjs.Component.extend({
vjs.Player.prototype.options_ = vjs.options;

vjs.Player.prototype.dispose = function(){
// this.isReady_ = false;
this.trigger('dispose');
// prevent dispose from being called twice
this.off('dispose');

// Kill reference to this player
vjs.players[this.id_] = null;
Expand Down
4 changes: 4 additions & 0 deletions test/unit/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ test('should dispose of component and children', function(){
var data = vjs.getData(comp.el());
var id = comp.el()[vjs.expando];

var hasDisposed = false;
comp.on('dispose', function(){ hasDisposed = true; });

comp.dispose();

ok(hasDisposed, 'component fired dispose event');
ok(!comp.children(), 'component children were deleted');
ok(!comp.el(), 'component element was deleted');
ok(!child.children(), 'child children were deleted');
Expand Down

0 comments on commit a449cb0

Please sign in to comment.