Add “forall” support to WoltLab/WCF/CallbackList.forEach
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 22 May 2015 18:59:51 +0000 (20:59 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 22 May 2015 19:05:40 +0000 (21:05 +0200)
wcfsetup/install/files/js/WoltLab/WCF/CallbackList.js

index fab271bd75cbfddbbbe05845500e95cf15fb6078..f932b225cb954f14c23368831d59eac014c8b9d3 100644 (file)
@@ -46,13 +46,21 @@ define(['Dictionary'], function(Dictionary) {
                /**
                 * Invokes callback function on each registered callback.
                 * 
-                * @param       {string}                identifier      arbitrary string to group and identify callbacks
+                * @param       {string|null}           identifier      arbitrary string to group and identify callbacks.
+                *                                                      null is a wildcard to match every identifier
                 * @param       {function(function)}    callback        function called with the individual callback as parameter
                 */
                forEach: function(identifier, callback) {
-                       var callbacks = this._dictionary.get(identifier);
-                       if (callbacks !== undefined) {
-                               callbacks.forEach(callback);
+                       if (identifier === null) {
+                               this._dictionary.forEach(function(callbacks, identifier) {
+                                       callbacks.forEach(callback);
+                               });
+                       }
+                       else {
+                               var callbacks = this._dictionary.get(identifier);
+                               if (callbacks !== undefined) {
+                                       callbacks.forEach(callback);
+                               }
                        }
                }
        };