/
resolver.js
44 lines (35 loc) · 1.26 KB
/
resolver.js
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
43
44
import { createProxyForType, getProxyByType, isProxyType, isTypeBlacklisted } from './proxies';
import {
getComponentDisplayName,
isCompositeComponent,
isContextType,
isForwardType,
isLazyType,
isMemoType,
} from '../internal/reactUtils';
import configuration, { internalConfiguration } from '../configuration';
const shouldNotPatchComponent = type => isTypeBlacklisted(type);
export function resolveType(type, options = {}) {
// fast return
if (!isCompositeComponent(type) || isProxyType(type)) {
return type;
}
const element = { type };
// fast meta
if (typeof element === 'object') {
if (isLazyType(element) || isMemoType(element) || isForwardType(element) || isContextType(element)) {
return getProxyByType(type) || type;
}
}
const existingProxy = getProxyByType(type);
// cold API
if (shouldNotPatchComponent(type)) {
return existingProxy ? existingProxy.getCurrent() : type;
}
if (!existingProxy && configuration.onComponentCreate) {
configuration.onComponentCreate(type, getComponentDisplayName(type));
if (shouldNotPatchComponent(type)) return type;
}
const proxy = internalConfiguration.disableProxyCreation ? existingProxy : createProxyForType(type, options);
return proxy ? proxy.get() : type;
}