From 2d9712a51fd3e4e5483d288e1e3ada068648c2e3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 26 Aug 2016 15:45:46 -0700 Subject: [PATCH] =?UTF-8?q?[Refactor]=20use=20ShallowTraversal=E2=80=99s?= =?UTF-8?q?=20`nodeHasProperty`=20inside=20MountedTraversal=E2=80=99s=20`i?= =?UTF-8?q?nstHasProperty`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MountedTraversal.js | 24 +++++------------------- src/ShallowTraversal.js | 3 ++- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/MountedTraversal.js b/src/MountedTraversal.js index 649cec776..aa096f610 100644 --- a/src/MountedTraversal.js +++ b/src/MountedTraversal.js @@ -2,7 +2,6 @@ import isEmpty from 'lodash/isEmpty'; import isSubset from 'is-subset'; import { internalInstance, - coercePropValue, nodeEqual, propsOfNode, isFunctionalComponent, @@ -13,6 +12,9 @@ import { SELECTOR, nodeHasType, } from './Utils'; +import { + nodeHasProperty, +} from './ShallowTraversal'; import { isDOMComponent, isCompositeComponent, @@ -85,26 +87,10 @@ export function instHasType(inst, type) { export function instHasProperty(inst, propKey, stringifiedPropValue) { if (!isDOMComponent(inst)) return false; - const node = getNode(inst); - const nodeProps = propsOfNode(node); - const descriptor = Object.getOwnPropertyDescriptor(nodeProps, propKey); - if (descriptor && descriptor.get) { - return false; - } - const nodePropValue = nodeProps[propKey]; - - const propValue = coercePropValue(propKey, stringifiedPropValue); - // intentionally not matching node props that are undefined - if (nodePropValue === undefined) { - return false; - } - - if (propValue || propValue === 0) { - return nodePropValue === propValue; - } + const node = getNode(inst); - return Object.prototype.hasOwnProperty.call(nodeProps, propKey); + return nodeHasProperty(node, propKey, stringifiedPropValue); } // called with private inst diff --git a/src/ShallowTraversal.js b/src/ShallowTraversal.js index 3975af8e3..f97dd0b6a 100644 --- a/src/ShallowTraversal.js +++ b/src/ShallowTraversal.js @@ -86,13 +86,14 @@ export function nodeHasId(node, id) { export function nodeHasProperty(node, propKey, stringifiedPropValue) { const nodeProps = propsOfNode(node); - const propValue = coercePropValue(propKey, stringifiedPropValue); const descriptor = Object.getOwnPropertyDescriptor(nodeProps, propKey); if (descriptor && descriptor.get) { return false; } const nodePropValue = nodeProps[propKey]; + const propValue = coercePropValue(propKey, stringifiedPropValue); + if (nodePropValue === undefined) { return false; }