/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
v16.13.0
packages/react/src/ReactLazy.js
66 строк
2 KB
Dan Abramov
Use console directly instead of warning() modules (#17599)
14 дек 2019, 21:09
Не верифицирован
14 дек 2019, 21:09
0cf22a5
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import type {LazyComponent, Thenable} from 'shared/ReactLazyComponent'; import {REACT_LAZY_TYPE} from 'shared/ReactSymbols'; export function lazy<T, R>(ctor: () => Thenable<T, R>): LazyComponent<T> { let lazyType = { $$typeof: REACT_LAZY_TYPE, _ctor: ctor, // React uses these fields to store the result. _status: -1, _result: null, }; if (__DEV__) { // In production, this would just set it on the object. let defaultProps; let propTypes; Object.defineProperties(lazyType, { defaultProps: { configurable: true, get() { return defaultProps; }, set(newDefaultProps) { console.error( 'React.lazy(...): It is not supported to assign `defaultProps` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.', ); defaultProps = newDefaultProps; // Match production behavior more closely: Object.defineProperty(lazyType, 'defaultProps', { enumerable: true, }); }, }, propTypes: { configurable: true, get() { return propTypes; }, set(newPropTypes) { console.error( 'React.lazy(...): It is not supported to assign `propTypes` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.', ); propTypes = newPropTypes; // Match production behavior more closely: Object.defineProperty(lazyType, 'propTypes', { enumerable: true, }); }, }, }); } return lazyType; }