(hookName, data, next = noop)
| 28 | } |
| 29 | |
| 30 | callHook(hookName, data, next = noop) { |
| 31 | const queue = this._hooks[hookName]; |
| 32 | const catchPluginErrors = this.config.catchPluginErrors; |
| 33 | |
| 34 | const step = function (index) { |
| 35 | const hookFn = queue[index]; |
| 36 | |
| 37 | if (index >= queue.length) { |
| 38 | next(data); |
| 39 | } else if (typeof hookFn === 'function') { |
| 40 | const errTitle = 'Docsify plugin error'; |
| 41 | |
| 42 | if (hookFn.length === 2) { |
| 43 | try { |
| 44 | hookFn(data, result => { |
| 45 | data = result; |
| 46 | step(index + 1); |
| 47 | }); |
| 48 | } catch (err) { |
| 49 | if (catchPluginErrors) { |
| 50 | console.error(errTitle, err); |
| 51 | } else { |
| 52 | throw err; |
| 53 | } |
| 54 | |
| 55 | step(index + 1); |
| 56 | } |
| 57 | } else { |
| 58 | try { |
| 59 | const result = hookFn(data); |
| 60 | |
| 61 | data = result === undefined ? data : result; |
| 62 | step(index + 1); |
| 63 | } catch (err) { |
| 64 | if (catchPluginErrors) { |
| 65 | console.error(errTitle, err); |
| 66 | } else { |
| 67 | throw err; |
| 68 | } |
| 69 | |
| 70 | step(index + 1); |
| 71 | } |
| 72 | } |
| 73 | } else { |
| 74 | step(index + 1); |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | step(0); |
| 79 | } |
| 80 | }; |
| 81 | } |
no outgoing calls
no test coverage detected