Skip to content

Commit

Permalink
eventCascade helper to underpin event sequence helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbender committed Mar 1, 2012
1 parent 39daf59 commit 4a6893e
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions tests/jquery.testHelper.js
Expand Up @@ -155,28 +155,44 @@
},

eventSequence: function(event, fns, timedOut){
var fn = fns.shift(),
self = this;
var seq = [];
$.each(fns, function(i, fn) {
seq.push(fn);
if( i !== fns.length - 1) seq.push(event);
});

if( fn === undefined ) return;
this.eventCascade(seq);
},

// if a pagechange or defined event is never triggered
// continue in the sequence to alert possible failures
var warnTimer = setTimeout(function(){
self.eventSequence(event, fns, true);
}, 2000);
eventCascade: function( sequence, timedOut ) {
var args = sequence,
fn = args.shift(),
event = args.shift(),
self = this;

// bind the recursive call to the event
$.mobile.pageContainer.one(event, function(){
clearTimeout(warnTimer);
if( fn === undefined ) {
return;
}

// Let the current stack unwind before we fire off the next item in the sequence.
// TODO setTimeout(self.pageSequence, 0, [fns, event]);
setTimeout(function(){ self.eventSequence(event, fns); }, 0);
});
if( event ){
// if a pagechange or defined event is never triggered
// continue in the sequence to alert possible failures
var warnTimer = setTimeout(function(){
self.eventCascade(args, true);
}, 2000);

// bind the recursive call to the event
$.mobile.pageContainer.one(event, function(){
clearTimeout(warnTimer);

// Let the current stack unwind before we fire off the next item in the sequence.
// TODO setTimeout(self.pageSequence, 0, args);
setTimeout(function(){ self.eventCascade(args); }, 0);
});
}

// invoke the function which should, in some fashion,
// trigger the defined event
// trigger the next event
fn(timedOut);
},

Expand All @@ -203,7 +219,6 @@
deferred.resolve();
}
);

}
} else {
deferred.resolve();
Expand Down

0 comments on commit 4a6893e

Please sign in to comment.