Skip to content

Commit

Permalink
@imbcmdth fix potential triggerReady infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
heff committed Sep 29, 2015
1 parent e225fbf commit cd6c568
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,13 @@ class Component {
this.setTimeout(function(){
let readyQueue = this.readyQueue_;

// Reset Ready Queue
this.readyQueue_ = [];

if (readyQueue && readyQueue.length > 0) {
readyQueue.forEach(function(fn){
fn.call(this);
}, this);

// Reset Ready Queue
this.readyQueue_ = [];
}

// Allow for using event listeners also
Expand Down
4 changes: 3 additions & 1 deletion test/unit/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,13 @@ test('should not retrigger a listener when the listener calls triggerReady', fun
}
};

var comp = new vjs.Component(getFakePlayer(), {});
var comp = new Component(getFakePlayer(), {});

comp.ready(readyListener);
comp.triggerReady();

this.clock.tick(100);

equal(timesCalled, 1, 'triggerReady from inside a ready handler does not result in an infinite loop');
});

Expand Down

0 comments on commit cd6c568

Please sign in to comment.