mirror of
https://github.com/facebook/react.git
synced 2026-02-26 07:55:55 +00:00
* Introduce elementType field This will be used to store the wrapped type of an element. E.g. pure and lazy. The existing type field will be used for the unwrapped type within them. * Store the unwrapped type on the type field of lazy components * Use the raw tags for lazy components Instead, we check if the elementType and type are equal to test if we need to resolve props. This is slightly slower in the normal case but will yield less code and branching. * Clean up lazy branches * Collapse work tag numbering * Split IndeterminateComponent out from Lazy This way we don't have to check the type in a hacky way in the indeterminate path. Also, lets us deal with lazy that resolves to indeterminate and such. * Missing clean up in rebase
37 lines
869 B
JavaScript
37 lines
869 B
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
|
|
*/
|
|
|
|
export type Thenable<T, R> = {
|
|
then(resolve: (T) => mixed, reject: (mixed) => mixed): R,
|
|
};
|
|
|
|
export type LazyComponent<T> = {
|
|
$$typeof: Symbol | number,
|
|
_ctor: () => Thenable<{default: T}, mixed>,
|
|
_status: 0 | 1 | 2,
|
|
_result: any,
|
|
};
|
|
|
|
type ResolvedLazyComponent<T> = {
|
|
$$typeof: Symbol | number,
|
|
_ctor: () => Thenable<{default: T}, mixed>,
|
|
_status: 1,
|
|
_result: any,
|
|
};
|
|
|
|
export const Pending = 0;
|
|
export const Resolved = 1;
|
|
export const Rejected = 2;
|
|
|
|
export function refineResolvedLazyComponent<T>(
|
|
lazyComponent: LazyComponent<T>,
|
|
): ResolvedLazyComponent<T> | null {
|
|
return lazyComponent._status === Resolved ? lazyComponent._result : null;
|
|
}
|