Replace magic number 1 with ELEMENT_NODE (#13479)

* Replace magic number 1 with ELEMENT_NODE

* Add flow pragma to HTMLNodeType
This commit is contained in:
Heaven 2018-08-27 23:16:24 +08:00 committed by Nathan Hunzaker
parent 340bfd9393
commit d400d6d5ef
4 changed files with 8 additions and 6 deletions

View File

@ -694,7 +694,7 @@ const ReactDOM: Object = {
// Check if the container itself is a React root node.
const isContainerReactRoot =
container.nodeType === 1 &&
container.nodeType === ELEMENT_NODE &&
isValidContainer(container.parentNode) &&
!!container.parentNode._reactRootContainer;

View File

@ -530,7 +530,7 @@ export function didNotHydrateContainerInstance(
instance: Instance | TextInstance,
) {
if (__DEV__) {
if (instance.nodeType === 1) {
if (instance.nodeType === ELEMENT_NODE) {
warnForDeletedHydratableElement(parentContainer, (instance: any));
} else {
warnForDeletedHydratableText(parentContainer, (instance: any));
@ -545,7 +545,7 @@ export function didNotHydrateInstance(
instance: Instance | TextInstance,
) {
if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
if (instance.nodeType === 1) {
if (instance.nodeType === ELEMENT_NODE) {
warnForDeletedHydratableElement(parentInstance, (instance: any));
} else {
warnForDeletedHydratableText(parentInstance, (instance: any));

View File

@ -3,6 +3,8 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
/**

View File

@ -20,7 +20,7 @@ import {
import SyntheticEvent from 'events/SyntheticEvent';
import invariant from 'shared/invariant';
import lowPriorityWarning from 'shared/lowPriorityWarning';
import {ELEMENT_NODE} from '../shared/HTMLNodeType';
import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes';
const {findDOMNode} = ReactDOM;
@ -124,7 +124,7 @@ function validateClassInstance(inst, methodName) {
const stringified = '' + inst;
if (Array.isArray(inst)) {
received = 'an array';
} else if (inst && inst.nodeType === 1 && inst.tagName) {
} else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
received = 'a DOM node';
} else if (stringified === '[object Object]') {
received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
@ -169,7 +169,7 @@ const ReactTestUtils = {
},
isDOMComponent: function(inst) {
return !!(inst && inst.nodeType === 1 && inst.tagName);
return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
},
isDOMComponentElement: function(inst) {