Constconst mountScript = pendingFn(
(url: string) => `script:${url}`,
({ scope, getPendingCount }, url: string) => {
const existing = document.getElementById(scope);
if (existing) return { element: existing };
return loadScript(url);
},
);
await Promise.all([mountScript('/lib.js'), mountScript('/lib.js')]);
感知 pending 状态的 inflight 去重(全局实例)
fn 的第一个参数为 PendingFnParams,包含 scope 和 getPendingCount, 允许根据 pending 状态做自定义处理(如短路检查、日志等)。 返回的函数剥掉 PendingFnParams,只暴露业务参数。
全局实例注意:静态 scope 必须在整个应用内唯一。HMR 场景下请改用 createPending 创建模块级独立实例。