forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactLazyComponent.js
More file actions
42 lines (36 loc) · 1009 Bytes
/
ReactLazyComponent.js
File metadata and controls
42 lines (36 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* 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 getResultFromResolvedLazyComponent<T>(
lazyComponent: ResolvedLazyComponent<T>,
): T {
return lazyComponent._result;
}
export function refineResolvedLazyComponent<T>(
lazyComponent: LazyComponent<T>,
): ResolvedLazyComponent<T> | null {
return lazyComponent._status === Resolved ? lazyComponent._result : null;
}