| | 1 | this["wp"] = this["wp"] || {}; this["wp"]["hooks"] = |
| | 2 | /******/ (function(modules) { // webpackBootstrap |
| | 3 | /******/ // The module cache |
| | 4 | /******/ var installedModules = {}; |
| | 5 | /******/ |
| | 6 | /******/ // The require function |
| | 7 | /******/ function __webpack_require__(moduleId) { |
| | 8 | /******/ |
| | 9 | /******/ // Check if module is in cache |
| | 10 | /******/ if(installedModules[moduleId]) { |
| | 11 | /******/ return installedModules[moduleId].exports; |
| | 12 | /******/ } |
| | 13 | /******/ // Create a new module (and put it into the cache) |
| | 14 | /******/ var module = installedModules[moduleId] = { |
| | 15 | /******/ i: moduleId, |
| | 16 | /******/ l: false, |
| | 17 | /******/ exports: {} |
| | 18 | /******/ }; |
| | 19 | /******/ |
| | 20 | /******/ // Execute the module function |
| | 21 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| | 22 | /******/ |
| | 23 | /******/ // Flag the module as loaded |
| | 24 | /******/ module.l = true; |
| | 25 | /******/ |
| | 26 | /******/ // Return the exports of the module |
| | 27 | /******/ return module.exports; |
| | 28 | /******/ } |
| | 29 | /******/ |
| | 30 | /******/ |
| | 31 | /******/ // expose the modules object (__webpack_modules__) |
| | 32 | /******/ __webpack_require__.m = modules; |
| | 33 | /******/ |
| | 34 | /******/ // expose the module cache |
| | 35 | /******/ __webpack_require__.c = installedModules; |
| | 36 | /******/ |
| | 37 | /******/ // define getter function for harmony exports |
| | 38 | /******/ __webpack_require__.d = function(exports, name, getter) { |
| | 39 | /******/ if(!__webpack_require__.o(exports, name)) { |
| | 40 | /******/ Object.defineProperty(exports, name, { |
| | 41 | /******/ configurable: false, |
| | 42 | /******/ enumerable: true, |
| | 43 | /******/ get: getter |
| | 44 | /******/ }); |
| | 45 | /******/ } |
| | 46 | /******/ }; |
| | 47 | /******/ |
| | 48 | /******/ // getDefaultExport function for compatibility with non-harmony modules |
| | 49 | /******/ __webpack_require__.n = function(module) { |
| | 50 | /******/ var getter = module && module.__esModule ? |
| | 51 | /******/ function getDefault() { return module['default']; } : |
| | 52 | /******/ function getModuleExports() { return module; }; |
| | 53 | /******/ __webpack_require__.d(getter, 'a', getter); |
| | 54 | /******/ return getter; |
| | 55 | /******/ }; |
| | 56 | /******/ |
| | 57 | /******/ // Object.prototype.hasOwnProperty.call |
| | 58 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
| | 59 | /******/ |
| | 60 | /******/ // __webpack_public_path__ |
| | 61 | /******/ __webpack_require__.p = ""; |
| | 62 | /******/ |
| | 63 | /******/ // Load entry module and return exports |
| | 64 | /******/ return __webpack_require__(__webpack_require__.s = 13); |
| | 65 | /******/ }) |
| | 66 | /************************************************************************/ |
| | 67 | /******/ ([ |
| | 68 | /* 0 */ |
| | 69 | /***/ (function(module, exports, __webpack_require__) { |
| | 70 | |
| | 71 | "use strict"; |
| | 72 | |
| | 73 | |
| | 74 | Object.defineProperty(exports, "__esModule", { |
| | 75 | value: true |
| | 76 | }); |
| | 77 | /** |
| | 78 | * Validate a hookName string. |
| | 79 | * |
| | 80 | * @param {string} hookName The hook name to validate. Should be a non empty string containing |
| | 81 | * only numbers, letters, dashes, periods and underscores. Also, |
| | 82 | * the hook name cannot begin with `__`. |
| | 83 | * |
| | 84 | * @return {bool} Whether the hook name is valid. |
| | 85 | */ |
| | 86 | function validateHookName(hookName) { |
| | 87 | |
| | 88 | if ('string' !== typeof hookName || '' === hookName) { |
| | 89 | console.error('The hook name must be a non-empty string.'); |
| | 90 | return false; |
| | 91 | } |
| | 92 | |
| | 93 | if (/^__/.test(hookName)) { |
| | 94 | console.error('The hook name cannot begin with `__`.'); |
| | 95 | return false; |
| | 96 | } |
| | 97 | |
| | 98 | if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) { |
| | 99 | console.error('The hook name can only contain numbers, letters, dashes, periods and underscores.'); |
| | 100 | return false; |
| | 101 | } |
| | 102 | |
| | 103 | return true; |
| | 104 | } |
| | 105 | |
| | 106 | exports.default = validateHookName; |
| | 107 | |
| | 108 | /***/ }), |
| | 109 | /* 1 */ |
| | 110 | /***/ (function(module, exports, __webpack_require__) { |
| | 111 | |
| | 112 | "use strict"; |
| | 113 | |
| | 114 | |
| | 115 | Object.defineProperty(exports, "__esModule", { |
| | 116 | value: true |
| | 117 | }); |
| | 118 | /** |
| | 119 | * Validate a namespace string. |
| | 120 | * |
| | 121 | * @param {string} namespace The namespace to validate - should take the form |
| | 122 | * `vendorName/pluginName/functionName`. |
| | 123 | * |
| | 124 | * @return {bool} Whether the namespace is valid. |
| | 125 | */ |
| | 126 | function validateNamespace(namespace) { |
| | 127 | |
| | 128 | if ('string' !== typeof namespace || '' === namespace) { |
| | 129 | console.error('The namespace must be a non-empty string.'); |
| | 130 | return false; |
| | 131 | } |
| | 132 | |
| | 133 | if (!/^[a-zA-Z][a-zA-Z0-9_.-/]*$/.test(namespace)) { |
| | 134 | console.error('The namespace can only contain numbers, letters, dashes, periods and underscores, plus the forward slash dividing slug and description in the namespace.'); |
| | 135 | return false; |
| | 136 | } |
| | 137 | |
| | 138 | if (!/^[a-zA-Z][a-zA-Z0-9_.-]*\/[a-zA-Z][a-zA-Z0-9_.-]*\/[a-zA-Z][a-zA-Z0-9_.-]*$/.test(namespace)) { |
| | 139 | console.error('The namespace must take the form `vendorName/pluginName/functionName`.'); |
| | 140 | return false; |
| | 141 | } |
| | 142 | |
| | 143 | return true; |
| | 144 | } |
| | 145 | |
| | 146 | exports.default = validateNamespace; |
| | 147 | |
| | 148 | /***/ }), |
| | 149 | /* 2 */, |
| | 150 | /* 3 */, |
| | 151 | /* 4 */, |
| | 152 | /* 5 */, |
| | 153 | /* 6 */, |
| | 154 | /* 7 */, |
| | 155 | /* 8 */, |
| | 156 | /* 9 */, |
| | 157 | /* 10 */, |
| | 158 | /* 11 */, |
| | 159 | /* 12 */, |
| | 160 | /* 13 */ |
| | 161 | /***/ (function(module, exports, __webpack_require__) { |
| | 162 | |
| | 163 | "use strict"; |
| | 164 | |
| | 165 | |
| | 166 | Object.defineProperty(exports, "__esModule", { |
| | 167 | value: true |
| | 168 | }); |
| | 169 | exports.didFilter = exports.didAction = exports.doingFilter = exports.doingAction = exports.currentFilter = exports.currentAction = exports.applyFilters = exports.doAction = exports.removeAllFilters = exports.removeAllActions = exports.hasFilter = exports.hasAction = exports.removeFilter = exports.removeAction = exports.addFilter = exports.addAction = undefined; |
| | 170 | |
| | 171 | var _hooks = __webpack_require__(14); |
| | 172 | |
| | 173 | var _hooks2 = _interopRequireDefault(_hooks); |
| | 174 | |
| | 175 | var _createAddHook = __webpack_require__(15); |
| | 176 | |
| | 177 | var _createAddHook2 = _interopRequireDefault(_createAddHook); |
| | 178 | |
| | 179 | var _createRemoveHook = __webpack_require__(16); |
| | 180 | |
| | 181 | var _createRemoveHook2 = _interopRequireDefault(_createRemoveHook); |
| | 182 | |
| | 183 | var _createHasHook = __webpack_require__(17); |
| | 184 | |
| | 185 | var _createHasHook2 = _interopRequireDefault(_createHasHook); |
| | 186 | |
| | 187 | var _createRunHook = __webpack_require__(18); |
| | 188 | |
| | 189 | var _createRunHook2 = _interopRequireDefault(_createRunHook); |
| | 190 | |
| | 191 | var _createCurrentHook = __webpack_require__(19); |
| | 192 | |
| | 193 | var _createCurrentHook2 = _interopRequireDefault(_createCurrentHook); |
| | 194 | |
| | 195 | var _createDoingHook = __webpack_require__(20); |
| | 196 | |
| | 197 | var _createDoingHook2 = _interopRequireDefault(_createDoingHook); |
| | 198 | |
| | 199 | var _createDidHook = __webpack_require__(21); |
| | 200 | |
| | 201 | var _createDidHook2 = _interopRequireDefault(_createDidHook); |
| | 202 | |
| | 203 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| | 204 | |
| | 205 | // Add action/filter functions. |
| | 206 | var addAction = exports.addAction = (0, _createAddHook2.default)(_hooks2.default.actions); |
| | 207 | var addFilter = exports.addFilter = (0, _createAddHook2.default)(_hooks2.default.filters); |
| | 208 | |
| | 209 | // Remove action/filter functions. |
| | 210 | var removeAction = exports.removeAction = (0, _createRemoveHook2.default)(_hooks2.default.actions); |
| | 211 | var removeFilter = exports.removeFilter = (0, _createRemoveHook2.default)(_hooks2.default.filters); |
| | 212 | |
| | 213 | // Has action/filter functions. |
| | 214 | var hasAction = exports.hasAction = (0, _createHasHook2.default)(_hooks2.default.actions); |
| | 215 | var hasFilter = exports.hasFilter = (0, _createHasHook2.default)(_hooks2.default.filters); |
| | 216 | |
| | 217 | // Remove all actions/filters functions. |
| | 218 | var removeAllActions = exports.removeAllActions = (0, _createRemoveHook2.default)(_hooks2.default.actions, true); |
| | 219 | var removeAllFilters = exports.removeAllFilters = (0, _createRemoveHook2.default)(_hooks2.default.filters, true); |
| | 220 | |
| | 221 | // Do action/apply filters functions. |
| | 222 | var doAction = exports.doAction = (0, _createRunHook2.default)(_hooks2.default.actions); |
| | 223 | var applyFilters = exports.applyFilters = (0, _createRunHook2.default)(_hooks2.default.filters, true); |
| | 224 | |
| | 225 | // Current action/filter functions. |
| | 226 | var currentAction = exports.currentAction = (0, _createCurrentHook2.default)(_hooks2.default.actions); |
| | 227 | var currentFilter = exports.currentFilter = (0, _createCurrentHook2.default)(_hooks2.default.filters); |
| | 228 | |
| | 229 | // Doing action/filter: true while a hook is being run. |
| | 230 | var doingAction = exports.doingAction = (0, _createDoingHook2.default)(_hooks2.default.actions); |
| | 231 | var doingFilter = exports.doingFilter = (0, _createDoingHook2.default)(_hooks2.default.filters); |
| | 232 | |
| | 233 | // Did action/filter functions. |
| | 234 | var didAction = exports.didAction = (0, _createDidHook2.default)(_hooks2.default.actions); |
| | 235 | var didFilter = exports.didFilter = (0, _createDidHook2.default)(_hooks2.default.filters); |
| | 236 | |
| | 237 | /***/ }), |
| | 238 | /* 14 */ |
| | 239 | /***/ (function(module, exports, __webpack_require__) { |
| | 240 | |
| | 241 | "use strict"; |
| | 242 | |
| | 243 | |
| | 244 | Object.defineProperty(exports, "__esModule", { |
| | 245 | value: true |
| | 246 | }); |
| | 247 | /** |
| | 248 | * Contains the registered hooks, keyed by hook type. Each hook type is an |
| | 249 | * array of objects with priority and callback of each registered hook. |
| | 250 | */ |
| | 251 | var HOOKS = { |
| | 252 | actions: {}, |
| | 253 | filters: {} |
| | 254 | }; |
| | 255 | |
| | 256 | exports.default = HOOKS; |
| | 257 | |
| | 258 | /***/ }), |
| | 259 | /* 15 */ |
| | 260 | /***/ (function(module, exports, __webpack_require__) { |
| | 261 | |
| | 262 | "use strict"; |
| | 263 | |
| | 264 | |
| | 265 | Object.defineProperty(exports, "__esModule", { |
| | 266 | value: true |
| | 267 | }); |
| | 268 | |
| | 269 | var _validateNamespace = __webpack_require__(1); |
| | 270 | |
| | 271 | var _validateNamespace2 = _interopRequireDefault(_validateNamespace); |
| | 272 | |
| | 273 | var _validateHookName = __webpack_require__(0); |
| | 274 | |
| | 275 | var _validateHookName2 = _interopRequireDefault(_validateHookName); |
| | 276 | |
| | 277 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| | 278 | |
| | 279 | /** |
| | 280 | * Returns a function which, when invoked, will add a hook. |
| | 281 | * |
| | 282 | * @param {Object} hooks Stored hooks, keyed by hook name. |
| | 283 | * |
| | 284 | * @return {Function} Function that adds a new hook. |
| | 285 | */ |
| | 286 | function createAddHook(hooks) { |
| | 287 | /** |
| | 288 | * Adds the hook to the appropriate hooks container. |
| | 289 | * |
| | 290 | * @param {string} hookName Name of hook to add |
| | 291 | * @param {string} namespace The unique namespace identifying the callback in the form `vendorName/pluginName/functionName`. |
| | 292 | * @param {Function} callback Function to call when the hook is run |
| | 293 | * @param {?number} priority Priority of this hook (default=10) |
| | 294 | */ |
| | 295 | return function addHook(hookName, namespace, callback) { |
| | 296 | var priority = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10; |
| | 297 | |
| | 298 | |
| | 299 | if (!(0, _validateHookName2.default)(hookName)) { |
| | 300 | return; |
| | 301 | } |
| | 302 | |
| | 303 | if (!(0, _validateNamespace2.default)(namespace)) { |
| | 304 | return; |
| | 305 | } |
| | 306 | |
| | 307 | if ('function' !== typeof callback) { |
| | 308 | console.error('The hook callback must be a function.'); |
| | 309 | return; |
| | 310 | } |
| | 311 | |
| | 312 | // Validate numeric priority |
| | 313 | if ('number' !== typeof priority) { |
| | 314 | console.error('If specified, the hook priority must be a number.'); |
| | 315 | return; |
| | 316 | } |
| | 317 | |
| | 318 | var handler = { callback: callback, priority: priority, namespace: namespace }; |
| | 319 | |
| | 320 | if (hooks.hasOwnProperty(hookName)) { |
| | 321 | // Find the correct insert index of the new hook. |
| | 322 | var handlers = hooks[hookName].handlers; |
| | 323 | var i = 0; |
| | 324 | while (i < handlers.length) { |
| | 325 | if (handlers[i].priority > priority) { |
| | 326 | break; |
| | 327 | } |
| | 328 | i++; |
| | 329 | } |
| | 330 | // Insert (or append) the new hook. |
| | 331 | handlers.splice(i, 0, handler); |
| | 332 | // We may also be currently executing this hook. If the callback |
| | 333 | // we're adding would come after the current callback, there's no |
| | 334 | // problem; otherwise we need to increase the execution index of |
| | 335 | // any other runs by 1 to account for the added element. |
| | 336 | (hooks.__current || []).forEach(function (hookInfo) { |
| | 337 | if (hookInfo.name === hookName && hookInfo.currentIndex >= i) { |
| | 338 | hookInfo.currentIndex++; |
| | 339 | } |
| | 340 | }); |
| | 341 | } else { |
| | 342 | // This is the first hook of its type. |
| | 343 | hooks[hookName] = { |
| | 344 | handlers: [handler], |
| | 345 | runs: 0 |
| | 346 | }; |
| | 347 | } |
| | 348 | }; |
| | 349 | } |
| | 350 | |
| | 351 | exports.default = createAddHook; |
| | 352 | |
| | 353 | /***/ }), |
| | 354 | /* 16 */ |
| | 355 | /***/ (function(module, exports, __webpack_require__) { |
| | 356 | |
| | 357 | "use strict"; |
| | 358 | |
| | 359 | |
| | 360 | Object.defineProperty(exports, "__esModule", { |
| | 361 | value: true |
| | 362 | }); |
| | 363 | |
| | 364 | var _validateNamespace = __webpack_require__(1); |
| | 365 | |
| | 366 | var _validateNamespace2 = _interopRequireDefault(_validateNamespace); |
| | 367 | |
| | 368 | var _validateHookName = __webpack_require__(0); |
| | 369 | |
| | 370 | var _validateHookName2 = _interopRequireDefault(_validateHookName); |
| | 371 | |
| | 372 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| | 373 | |
| | 374 | /** |
| | 375 | * Returns a function which, when invoked, will remove a specified hook or all |
| | 376 | * hooks by the given name. |
| | 377 | * |
| | 378 | * @param {Object} hooks Stored hooks, keyed by hook name. |
| | 379 | * @param {bool} removeAll Whether to remove all callbacks for a hookName, without regard to namespace. Used to create `removeAll*` functions. |
| | 380 | * |
| | 381 | * @return {Function} Function that removes hooks. |
| | 382 | */ |
| | 383 | function createRemoveHook(hooks, removeAll) { |
| | 384 | /** |
| | 385 | * Removes the specified callback (or all callbacks) from the hook with a |
| | 386 | * given hookName and namespace. |
| | 387 | * |
| | 388 | * @param {string} hookName The name of the hook to modify. |
| | 389 | * @param {string} namespace The unique namespace identifying the callback in the form `vendorName/pluginName/functionName`. |
| | 390 | * |
| | 391 | * @return {number} The number of callbacks removed. |
| | 392 | */ |
| | 393 | return function removeHook(hookName, namespace) { |
| | 394 | |
| | 395 | if (!(0, _validateHookName2.default)(hookName)) { |
| | 396 | return; |
| | 397 | } |
| | 398 | |
| | 399 | if (!removeAll && !(0, _validateNamespace2.default)(namespace)) { |
| | 400 | return; |
| | 401 | } |
| | 402 | |
| | 403 | // Bail if no hooks exist by this name |
| | 404 | if (!hooks.hasOwnProperty(hookName)) { |
| | 405 | return 0; |
| | 406 | } |
| | 407 | |
| | 408 | var handlersRemoved = 0; |
| | 409 | |
| | 410 | if (removeAll) { |
| | 411 | handlersRemoved = hooks[hookName].handlers.length; |
| | 412 | hooks[hookName] = { |
| | 413 | runs: hooks[hookName].runs, |
| | 414 | handlers: [] |
| | 415 | }; |
| | 416 | } else { |
| | 417 | // Try to find the specified callback to remove. |
| | 418 | var handlers = hooks[hookName].handlers; |
| | 419 | |
| | 420 | var _loop = function _loop(i) { |
| | 421 | if (handlers[i].namespace === namespace) { |
| | 422 | handlers.splice(i, 1); |
| | 423 | handlersRemoved++; |
| | 424 | // This callback may also be part of a hook that is |
| | 425 | // currently executing. If the callback we're removing |
| | 426 | // comes after the current callback, there's no problem; |
| | 427 | // otherwise we need to decrease the execution index of any |
| | 428 | // other runs by 1 to account for the removed element. |
| | 429 | (hooks.__current || []).forEach(function (hookInfo) { |
| | 430 | if (hookInfo.name === hookName && hookInfo.currentIndex >= i) { |
| | 431 | hookInfo.currentIndex--; |
| | 432 | } |
| | 433 | }); |
| | 434 | } |
| | 435 | }; |
| | 436 | |
| | 437 | for (var i = handlers.length - 1; i >= 0; i--) { |
| | 438 | _loop(i); |
| | 439 | } |
| | 440 | } |
| | 441 | |
| | 442 | return handlersRemoved; |
| | 443 | }; |
| | 444 | } |
| | 445 | |
| | 446 | exports.default = createRemoveHook; |
| | 447 | |
| | 448 | /***/ }), |
| | 449 | /* 17 */ |
| | 450 | /***/ (function(module, exports, __webpack_require__) { |
| | 451 | |
| | 452 | "use strict"; |
| | 453 | |
| | 454 | |
| | 455 | Object.defineProperty(exports, "__esModule", { |
| | 456 | value: true |
| | 457 | }); |
| | 458 | /** |
| | 459 | * Returns a function which, when invoked, will return whether any handlers are |
| | 460 | * attached to a particular hook. |
| | 461 | * |
| | 462 | * @param {Object} hooks Stored hooks, keyed by hook name. |
| | 463 | * |
| | 464 | * @return {Function} Function that returns whether any handlers are |
| | 465 | * attached to a particular hook. |
| | 466 | */ |
| | 467 | function createHasHook(hooks) { |
| | 468 | /** |
| | 469 | * Returns how many handlers are attached for the given hook. |
| | 470 | * |
| | 471 | * @param {string} hookName The name of the hook to check for. |
| | 472 | * |
| | 473 | * @return {number} The number of handlers that are attached to |
| | 474 | * the given hook. |
| | 475 | */ |
| | 476 | return function hasHook(hookName) { |
| | 477 | return hooks.hasOwnProperty(hookName) ? hooks[hookName].handlers.length : 0; |
| | 478 | }; |
| | 479 | } |
| | 480 | |
| | 481 | exports.default = createHasHook; |
| | 482 | |
| | 483 | /***/ }), |
| | 484 | /* 18 */ |
| | 485 | /***/ (function(module, exports, __webpack_require__) { |
| | 486 | |
| | 487 | "use strict"; |
| | 488 | |
| | 489 | |
| | 490 | Object.defineProperty(exports, "__esModule", { |
| | 491 | value: true |
| | 492 | }); |
| | 493 | |
| | 494 | var _validateHookName = __webpack_require__(0); |
| | 495 | |
| | 496 | var _validateHookName2 = _interopRequireDefault(_validateHookName); |
| | 497 | |
| | 498 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| | 499 | |
| | 500 | /** |
| | 501 | * Returns a function which, when invoked, will execute all callbacks |
| | 502 | * registered to a hook of the specified type, optionally returning the final |
| | 503 | * value of the call chain. |
| | 504 | * |
| | 505 | * @param {Object} hooks Stored hooks, keyed by hook name. |
| | 506 | * @param {?bool} returnFirstArg Whether each hook callback is expected to |
| | 507 | * return its first argument. |
| | 508 | * |
| | 509 | * @return {Function} Function that runs hook callbacks. |
| | 510 | */ |
| | 511 | function createRunHook(hooks, returnFirstArg) { |
| | 512 | /** |
| | 513 | * Runs all callbacks for the specified hook. |
| | 514 | * |
| | 515 | * @param {string} hookName The name of the hook to run. |
| | 516 | * @param {...*} args Arguments to pass to the hook callbacks. |
| | 517 | * |
| | 518 | * @return {*} Return value of runner, if applicable. |
| | 519 | */ |
| | 520 | return function runHooks(hookName) { |
| | 521 | |
| | 522 | if (!(0, _validateHookName2.default)(hookName)) { |
| | 523 | return; |
| | 524 | } |
| | 525 | |
| | 526 | if (!hooks.hasOwnProperty(hookName)) { |
| | 527 | hooks[hookName] = { |
| | 528 | runs: 0, |
| | 529 | handlers: [] |
| | 530 | }; |
| | 531 | } |
| | 532 | |
| | 533 | var handlers = hooks[hookName].handlers; |
| | 534 | |
| | 535 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
| | 536 | args[_key - 1] = arguments[_key]; |
| | 537 | } |
| | 538 | |
| | 539 | if (!handlers.length) { |
| | 540 | return returnFirstArg ? args[0] : undefined; |
| | 541 | } |
| | 542 | |
| | 543 | var hookInfo = { |
| | 544 | name: hookName, |
| | 545 | currentIndex: 0 |
| | 546 | }; |
| | 547 | |
| | 548 | hooks.__current = hooks.__current || []; |
| | 549 | hooks.__current.push(hookInfo); |
| | 550 | hooks[hookName].runs++; |
| | 551 | |
| | 552 | var maybeReturnValue = args[0]; |
| | 553 | |
| | 554 | while (hookInfo.currentIndex < handlers.length) { |
| | 555 | var handler = handlers[hookInfo.currentIndex]; |
| | 556 | maybeReturnValue = handler.callback.apply(null, args); |
| | 557 | if (returnFirstArg) { |
| | 558 | args[0] = maybeReturnValue; |
| | 559 | } |
| | 560 | hookInfo.currentIndex++; |
| | 561 | } |
| | 562 | |
| | 563 | hooks.__current.pop(); |
| | 564 | |
| | 565 | if (returnFirstArg) { |
| | 566 | return maybeReturnValue; |
| | 567 | } |
| | 568 | }; |
| | 569 | } |
| | 570 | |
| | 571 | exports.default = createRunHook; |
| | 572 | |
| | 573 | /***/ }), |
| | 574 | /* 19 */ |
| | 575 | /***/ (function(module, exports, __webpack_require__) { |
| | 576 | |
| | 577 | "use strict"; |
| | 578 | |
| | 579 | |
| | 580 | Object.defineProperty(exports, "__esModule", { |
| | 581 | value: true |
| | 582 | }); |
| | 583 | /** |
| | 584 | * Returns a function which, when invoked, will return the name of the |
| | 585 | * currently running hook, or `null` if no hook of the given type is currently |
| | 586 | * running. |
| | 587 | * |
| | 588 | * @param {Object} hooks Stored hooks, keyed by hook name. |
| | 589 | * |
| | 590 | * @return {Function} Function that returns the current hook. |
| | 591 | */ |
| | 592 | function createCurrentHook(hooks, returnFirstArg) { |
| | 593 | /** |
| | 594 | * Returns the name of the currently running hook, or `null` if no hook of |
| | 595 | * the given type is currently running. |
| | 596 | * |
| | 597 | * @return {?string} The name of the currently running hook, or |
| | 598 | * `null` if no hook is currently running. |
| | 599 | */ |
| | 600 | return function currentHook() { |
| | 601 | if (!hooks.__current || !hooks.__current.length) { |
| | 602 | return null; |
| | 603 | } |
| | 604 | |
| | 605 | return hooks.__current[hooks.__current.length - 1].name; |
| | 606 | }; |
| | 607 | } |
| | 608 | |
| | 609 | exports.default = createCurrentHook; |
| | 610 | |
| | 611 | /***/ }), |
| | 612 | /* 20 */ |
| | 613 | /***/ (function(module, exports, __webpack_require__) { |
| | 614 | |
| | 615 | "use strict"; |
| | 616 | |
| | 617 | |
| | 618 | Object.defineProperty(exports, "__esModule", { |
| | 619 | value: true |
| | 620 | }); |
| | 621 | /** |
| | 622 | * Returns a function which, when invoked, will return whether a hook is |
| | 623 | * currently being executed. |
| | 624 | * |
| | 625 | * @param {Object} hooks Stored hooks, keyed by hook name. |
| | 626 | * |
| | 627 | * @return {Function} Function that returns whether a hook is currently |
| | 628 | * being executed. |
| | 629 | */ |
| | 630 | function createDoingHook(hooks) { |
| | 631 | /** |
| | 632 | * Returns whether a hook is currently being executed. |
| | 633 | * |
| | 634 | * @param {?string} hookName The name of the hook to check for. If |
| | 635 | * omitted, will check for any hook being executed. |
| | 636 | * |
| | 637 | * @return {bool} Whether the hook is being executed. |
| | 638 | */ |
| | 639 | return function doingHook(hookName) { |
| | 640 | // If the hookName was not passed, check for any current hook. |
| | 641 | if ('undefined' === typeof hookName) { |
| | 642 | return 'undefined' !== typeof hooks.__current[0]; |
| | 643 | } |
| | 644 | |
| | 645 | // Return the __current hook. |
| | 646 | return hooks.__current[0] ? hookName === hooks.__current[0].name : false; |
| | 647 | }; |
| | 648 | } |
| | 649 | |
| | 650 | exports.default = createDoingHook; |
| | 651 | |
| | 652 | /***/ }), |
| | 653 | /* 21 */ |
| | 654 | /***/ (function(module, exports, __webpack_require__) { |
| | 655 | |
| | 656 | "use strict"; |
| | 657 | |
| | 658 | |
| | 659 | Object.defineProperty(exports, "__esModule", { |
| | 660 | value: true |
| | 661 | }); |
| | 662 | |
| | 663 | var _validateHookName = __webpack_require__(0); |
| | 664 | |
| | 665 | var _validateHookName2 = _interopRequireDefault(_validateHookName); |
| | 666 | |
| | 667 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| | 668 | |
| | 669 | /** |
| | 670 | * Returns a function which, when invoked, will return the number of times a |
| | 671 | * hook has been called. |
| | 672 | * |
| | 673 | * @param {Object} hooks Stored hooks, keyed by hook name. |
| | 674 | * |
| | 675 | * @return {Function} Function that returns a hook's call count. |
| | 676 | */ |
| | 677 | function createDidHook(hooks) { |
| | 678 | /** |
| | 679 | * Returns the number of times an action has been fired. |
| | 680 | * |
| | 681 | * @param {string} hookName The hook name to check. |
| | 682 | * |
| | 683 | * @return {number} The number of times the hook has run. |
| | 684 | */ |
| | 685 | return function didHook(hookName) { |
| | 686 | |
| | 687 | if (!(0, _validateHookName2.default)(hookName)) { |
| | 688 | return; |
| | 689 | } |
| | 690 | |
| | 691 | return hooks.hasOwnProperty(hookName) && hooks[hookName].runs ? hooks[hookName].runs : 0; |
| | 692 | }; |
| | 693 | } |
| | 694 | |
| | 695 | exports.default = createDidHook; |
| | 696 | |
| | 697 | /***/ }) |
| | 698 | /******/ ]); |