| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | // ATTENTION |
| 11 | // When adding new symbols to this file, |
| 12 | // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols' |
| 13 | |
| 14 | // The Symbol used to tag the ReactElement-like types. |
| 15 | export const REACT_LEGACY_ELEMENT_TYPE: symbol = Symbol.for('react.element'); |
| 16 | export const REACT_ELEMENT_TYPE: symbol = Symbol.for( |
| 17 | 'react.transitional.element', |
| 18 | ); |
| 19 | export const REACT_PORTAL_TYPE: symbol = Symbol.for('react.portal'); |
| 20 | export const REACT_FRAGMENT_TYPE: symbol = Symbol.for('react.fragment'); |
| 21 | export const REACT_STRICT_MODE_TYPE: symbol = Symbol.for('react.strict_mode'); |
| 22 | export const REACT_PROFILER_TYPE: symbol = Symbol.for('react.profiler'); |
| 23 | export const REACT_CONSUMER_TYPE: symbol = Symbol.for('react.consumer'); |
| 24 | export const REACT_CONTEXT_TYPE: symbol = Symbol.for('react.context'); |
| 25 | export const REACT_FORWARD_REF_TYPE: symbol = Symbol.for('react.forward_ref'); |
| 26 | export const REACT_SUSPENSE_TYPE: symbol = Symbol.for('react.suspense'); |
| 27 | export const REACT_SUSPENSE_LIST_TYPE: symbol = Symbol.for( |
| 28 | 'react.suspense_list', |
| 29 | ); |
| 30 | export const REACT_MEMO_TYPE: symbol = Symbol.for('react.memo'); |
| 31 | export const REACT_LAZY_TYPE: symbol = Symbol.for('react.lazy'); |
| 32 | export const REACT_SCOPE_TYPE: symbol = Symbol.for('react.scope'); |
| 33 | export const REACT_ACTIVITY_TYPE: symbol = Symbol.for('react.activity'); |
| 34 | export const REACT_LEGACY_HIDDEN_TYPE: symbol = Symbol.for( |
| 35 | 'react.legacy_hidden', |
| 36 | ); |
| 37 | export const REACT_TRACING_MARKER_TYPE: symbol = Symbol.for( |
| 38 | 'react.tracing_marker', |
| 39 | ); |
| 40 | |
| 41 | export const REACT_MEMO_CACHE_SENTINEL: symbol = Symbol.for( |
| 42 | 'react.memo_cache_sentinel', |
| 43 | ); |
| 44 | |
| 45 | export const REACT_VIEW_TRANSITION_TYPE: symbol = Symbol.for( |
| 46 | 'react.view_transition', |
| 47 | ); |
| 48 | |
| 49 | export const REACT_RECOVERABLE_TYPE: symbol = Symbol.for('react.recoverable'); |
| 50 | |
| 51 | const MAYBE_ITERATOR_SYMBOL = Symbol.iterator; |
| 52 | const FAUX_ITERATOR_SYMBOL = '@@iterator'; |
| 53 | |
| 54 | export function getIteratorFn(maybeIterable: ?any): ?() => ?Iterator<any> { |
| 55 | if (maybeIterable === null || typeof maybeIterable !== 'object') { |
| 56 | return null; |
| 57 | } |
| 58 | const maybeIterator = |
| 59 | (MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) || |
| 60 | maybeIterable[FAUX_ITERATOR_SYMBOL]; |
| 61 | if (typeof maybeIterator === 'function') { |
| 62 | return maybeIterator; |
| 63 | } |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | export const ASYNC_ITERATOR = Symbol.asyncIterator; |
| 68 | |
| 69 | export const REACT_OPTIMISTIC_KEY: ReactOptimisticKey = Symbol.for( |
| 70 | 'react.optimistic_key', |
| 71 | ) as any; |
| 72 | |
| 73 | // This is actually a symbol but Flow doesn't support comparison of symbols to refine. |
| 74 | // We use a boolean since in our code we often expect string (key) or number (index), |
| 75 | // so by pretending to be a boolean we cover a lot of cases that don't consider this case. |
| 76 | export type ReactOptimisticKey = true; |