1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

setup browserify and requires

This commit is contained in:
fchasen 2015-12-03 23:41:49 -05:00
parent 76aab85dc4
commit 91d1df14b1
25 changed files with 4789 additions and 4441 deletions

41
src/hook.js Normal file
View file

@ -0,0 +1,41 @@
var RSVP = require('rsvp');
//-- Hooks allow for injecting functions that must all complete in order before finishing
// They will execute in parallel but all must finish before continuing
// Functions may return a promise if they are asycn.
// this.content = new EPUBJS.Hook();
// this.content.register(function(){});
// this.content.trigger(args).then(function(){});
function Hook(context){
this.context = context || this;
this.hooks = [];
};
// Adds a function to be run before a hook completes
Hook.prototype.register = function(func){
this.hooks.push(func);
};
// Triggers a hook to run all functions
Hook.prototype.trigger = function(){
var args = arguments;
var context = this.context;
var promises = [];
this.hooks.forEach(function(task, i) {
var executing = task.apply(context, args);
if(executing && typeof executing["then"] === "function") {
// Task is a function that returns a promise
promises.push(executing);
}
// Otherwise Task resolves immediately, continue
});
return RSVP.all(promises);
};
module.exports = Hook;