Skip to content

Commit

Permalink
Allow Hooks#add() to take an object literal with multiple hook additions
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed Feb 16, 2017
1 parent aad2fac commit cf2b6bc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
14 changes: 13 additions & 1 deletion bliss.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,21 @@ extend($, {

$.Hooks = new $.Class({
add: function (name, callback, first) {
if (typeof arguments[0] != "string") {
// Multiple hooks
for (var name in arguments[0]) {
this.add(name, arguments[0][name], arguments[1]);
}

return;
}

(Array.isArray(name)? name : [name]).forEach(function(name) {
this[name] = this[name] || [];
this[name][first? "unshift" : "push"](callback);

if (callback) {
this[name][first? "unshift" : "push"](callback);
}
}, this);
},

Expand Down
Loading

0 comments on commit cf2b6bc

Please sign in to comment.