钩子的约定
¥Conventions of hooks
钩子是 chain 的一部分,即使该链仅包含一个自定义(用户提供的)钩子和始终存在的默认钩子。钩子函数嵌套:每个函数都必须始终返回一个普通对象,并且链接是由于每个函数调用 next<hookName>()
而发生的,next<hookName>()
是对后续加载器钩子的引用(按 LIFO 顺序)。
¥Hooks are part of a chain, even if that chain consists of only one
custom (user-provided) hook and the default hook, which is always present. Hook
functions nest: each one must always return a plain object, and chaining happens
as a result of each function calling next<hookName>()
, which is a reference to
the subsequent loader's hook (in LIFO order).
返回缺少必需属性的值的钩子会触发异常。没有调用 next<hookName>()
和没有返回 shortCircuit: true
就返回的钩子也会触发异常。这些错误有助于防止链中的意外中断。从钩子返回 shortCircuit: true
表示该链有意在你的钩子处结束。
¥A hook that returns a value lacking a required property triggers an exception. A
hook that returns without calling next<hookName>()
and without returning
shortCircuit: true
also triggers an exception. These errors are to help
prevent unintentional breaks in the chain. Return shortCircuit: true
from a
hook to signal that the chain is intentionally ending at your hook.