This commit is contained in:
2019-07-25 01:10:19 +05:30
2 changed files with 18 additions and 12 deletions
+4 -7
View File
@@ -1,5 +1,5 @@
import { FiberNode } from "./mocked-types";
import { isNotHtmlLike } from "./utils";
import { isNodeNotHtmlLike } from "./utils";
function findNodeByComponentName(
node: FiberNode | null,
@@ -9,8 +9,7 @@ function findNodeByComponentName(
return null;
}
if (isNotHtmlLike(node) && node.type.name === expectedName) {
// console.debug("Found node " + node);
if (isNodeNotHtmlLike(node) && node.type.name === expectedName) {
return node;
}
@@ -38,8 +37,7 @@ function findNodeByComponent(
return null;
}
if (isNotHtmlLike(node) && node.type === expectedClassOrFunction) {
// console.debug("Found node " + node);
if (isNodeNotHtmlLike(node) && node.type === expectedClassOrFunction) {
return node;
}
@@ -67,8 +65,7 @@ function findNodeByComponentInstance(
return null;
}
if (isNotHtmlLike(node) && node.stateNode === expectedClassInstance) {
// console.debug("Found node " + node);
if (isNodeNotHtmlLike(node) && node.stateNode === expectedClassInstance) {
return node;
}
+14 -5
View File
@@ -1,11 +1,20 @@
import { FiberNode, FiberNodeisHTMLLike } from './mocked-types';
import * as React from 'react';
import { FiberNode, FiberNodeisHTMLLike, FiberNodeForFunctionComponent, FiberNodeForComponentClass } from './mocked-types';
function isHtmlLike(node: FiberNode): node is FiberNodeisHTMLLike {
function isNodeHtmlLike(node: FiberNode): node is FiberNodeisHTMLLike {
return (typeof node.type === "string") || node.type === null;
}
function isNotHtmlLike(node: FiberNode): node is Exclude<FiberNode, FiberNodeisHTMLLike> {
return !isHtmlLike(node);
function isNodeNotHtmlLike(node: FiberNode): node is Exclude<FiberNode, FiberNodeisHTMLLike> {
return !isNodeHtmlLike(node);
}
export { isHtmlLike, isNotHtmlLike };
function isNodeFunctionComponent(node: FiberNode): node is FiberNodeForFunctionComponent {
return isNodeNotHtmlLike(node) && node.stateNode === null;
}
function isNodeComponentClass(node: FiberNode): node is FiberNodeForComponentClass {
return isNodeNotHtmlLike(node) && (node.stateNode instanceof React.Component);
}
export { isNodeHtmlLike, isNodeNotHtmlLike, isNodeFunctionComponent, isNodeComponentClass };