mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
Removes support for using arbitrary promises as the type of a React
element. Instead, promises must be wrapped in React.lazy. This gives us
flexibility later if we need to change the protocol.
The reason is that promises do not provide a way to call their
constructor multiple times. For example:
const promiseForA = new Promise(resolve => {
fetchA(a => resolve(a));
});
Given a reference to `promiseForA`, there's no way to call `fetchA`
again. Calling `then` on the promise doesn't run the constructor again;
it only attaches another listener.
In the future we will likely introduce an API like `React.eager` that
is similar to `lazy` but eagerly calls the constructor. That gives us
the ability to call the constructor multiple times. E.g. to increase
the priority, or to retry if the first operation failed.
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
/**
|
|
* 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.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
// nor polyfill, then a plain number is used for performance.
|
|
const hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
|
|
export const REACT_ELEMENT_TYPE = hasSymbol
|
|
? Symbol.for('react.element')
|
|
: 0xeac7;
|
|
export const REACT_PORTAL_TYPE = hasSymbol
|
|
? Symbol.for('react.portal')
|
|
: 0xeaca;
|
|
export const REACT_FRAGMENT_TYPE = hasSymbol
|
|
? Symbol.for('react.fragment')
|
|
: 0xeacb;
|
|
export const REACT_STRICT_MODE_TYPE = hasSymbol
|
|
? Symbol.for('react.strict_mode')
|
|
: 0xeacc;
|
|
export const REACT_PROFILER_TYPE = hasSymbol
|
|
? Symbol.for('react.profiler')
|
|
: 0xead2;
|
|
export const REACT_PROVIDER_TYPE = hasSymbol
|
|
? Symbol.for('react.provider')
|
|
: 0xeacd;
|
|
export const REACT_CONTEXT_TYPE = hasSymbol
|
|
? Symbol.for('react.context')
|
|
: 0xeace;
|
|
export const REACT_CONCURRENT_MODE_TYPE = hasSymbol
|
|
? Symbol.for('react.concurrent_mode')
|
|
: 0xeacf;
|
|
export const REACT_FORWARD_REF_TYPE = hasSymbol
|
|
? Symbol.for('react.forward_ref')
|
|
: 0xead0;
|
|
export const REACT_SUSPENSE_TYPE = hasSymbol
|
|
? Symbol.for('react.suspense')
|
|
: 0xead1;
|
|
export const REACT_PURE_TYPE = hasSymbol ? Symbol.for('react.pure') : 0xead3;
|
|
export const REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
|
|
|
const MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
const FAUX_ITERATOR_SYMBOL = '@@iterator';
|
|
|
|
export function getIteratorFn(maybeIterable: ?any): ?() => ?Iterator<*> {
|
|
if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
|
return null;
|
|
}
|
|
const maybeIterator =
|
|
(MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
|
|
maybeIterable[FAUX_ITERATOR_SYMBOL];
|
|
if (typeof maybeIterator === 'function') {
|
|
return maybeIterator;
|
|
}
|
|
return null;
|
|
}
|