跳到主要内容

React DOM

作用

测试执行

在测试环境展示检验环境并给出相关文本错误警示:“React 依赖于 Map 和 Set 内置类型。请确保在较旧的浏览器中加载 polyfill。”

if (__DEV__) {
if (
typeof Map !== 'function' ||
Map.prototype == null ||
typeof Map.prototype.forEach !== 'function' ||
typeof Set !== 'function' ||
Set.prototype == null ||
typeof Set.prototype.clear !== 'function' ||
typeof Set.prototype.forEach !== 'function'
) {
console.error(
'React depends on Map and Set built-in types. Make sure that you load a ' +
'polyfill in older browsers. https://reactjs.org/link/react-polyfills',
);
}
}

批量更新

function batchedUpdates<A, R>(fn: (a: A) => R, a: A): R {
// batchedUpdates is now just a passthrough noop
// batchedUpdates 现在只是一个透传的空操作
return fn(a);
}

创建入口

备注
function createPortal(
children: ReactNodeList,
container: Element | DocumentFragment,
key: ?string = null,
): React$Portal {
if (!isValidContainer(container)) {
throw new Error('Target container is not a DOM element.');
}

// TODO: pass ReactDOM portal implementation as third argument
// 待办:将 ReactDOM 入口实现作为第三个参数传递
return createPortalImpl(children, container, null, key);
}

转导

作为一个中间文件,整理并导出了以下内容: