Skip to content

Commit

Permalink
chore: cleanup resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jul 4, 2019
1 parent c435eaa commit 8d14827
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/reactHotLoader.js
Expand Up @@ -128,12 +128,12 @@ const reactHotLoader = {
configuration.showReactDomPatchNotification = false;

if (ReactDOM.setHotTypeResolver) {
configuration.intergratedResolver = true;
configuration.integratedResolver = true;
ReactDOM.setHotTypeResolver(resolveType);
}
}

if (!configuration.intergratedResolver) {
if (!configuration.integratedResolver) {
/* eslint-enable */
if (!React.createElement.isPatchedByReactHotLoader) {
const originalCreateElement = React.createElement;
Expand Down
19 changes: 17 additions & 2 deletions src/reconciler/componentComparator.js
@@ -1,6 +1,13 @@
import { getIdByType, getProxyByType, getSignature, isColdType, updateProxyById } from './proxies';
import { hotComparisonOpen } from '../global/generation';
import { isForwardType, isMemoType, isReactClass, isReloadableComponent } from '../internal/reactUtils';
import {
isContextType,
isForwardType,
isLazyType,
isMemoType,
isReactClass,
isReloadableComponent,
} from '../internal/reactUtils';
import { areSwappable } from './utils';
import { PROXY_KEY, UNWRAP_PROXY } from '../proxy';
import { resolveType } from './resolver';
Expand Down Expand Up @@ -140,6 +147,14 @@ const compareComponents = (oldType, newType, setNewType, baseType) => {
return defaultResult;
}

if (isLazyType({ type: oldType })) {
return defaultResult;
}

if (isContextType({ type: oldType })) {
return defaultResult;
}

if (
typeof newType === 'function' &&
(defaultResult ||
Expand All @@ -164,7 +179,7 @@ const emptyMap = new WeakMap();

export const hotComponentCompare = (oldType, preNewType, setNewType, baseType) => {
const hotActive = hotComparisonOpen();
const newType = configuration.intergratedResolver ? resolveType(preNewType) : preNewType;
const newType = configuration.integratedResolver ? resolveType(preNewType) : preNewType;
let result = oldType === newType;

if (!hotActive) {
Expand Down
4 changes: 3 additions & 1 deletion src/reconciler/resolver.js
Expand Up @@ -2,6 +2,7 @@ import { createProxyForType, getProxyByType, isProxyType, isTypeBlacklisted } fr
import {
getComponentDisplayName,
isCompositeComponent,
isContextType,
isForwardType,
isLazyType,
isMemoType,
Expand All @@ -11,7 +12,8 @@ import configuration, { internalConfiguration } from '../configuration';
const shouldNotPatchComponent = type => isTypeBlacklisted(type);

export function resolveType(type, options = {}) {
if (isLazyType({ type }) || isMemoType({ type }) || isForwardType({ type })) {
const element = { type };
if (isLazyType(element) || isMemoType(element) || isForwardType(element) || isContextType(element)) {
return getProxyByType(type) || type;
}

Expand Down

0 comments on commit 8d14827

Please sign in to comment.