Skip to content

Commit

Permalink
[Refactor] use ShallowTraversal’s nodeHasProperty inside MountedTra…
Browse files Browse the repository at this point in the history
…versal’s `instHasProperty`.
  • Loading branch information
ljharb committed Aug 26, 2016
1 parent f76bc53 commit 2d9712a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
24 changes: 5 additions & 19 deletions src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import isEmpty from 'lodash/isEmpty';
import isSubset from 'is-subset';
import {
internalInstance,
coercePropValue,
nodeEqual,
propsOfNode,
isFunctionalComponent,
Expand All @@ -13,6 +12,9 @@ import {
SELECTOR,
nodeHasType,
} from './Utils';
import {
nodeHasProperty,
} from './ShallowTraversal';
import {
isDOMComponent,
isCompositeComponent,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/ShallowTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 2d9712a

Please sign in to comment.