diff --git a/src/core/getComponentKey.js b/src/core/getComponentKey.js deleted file mode 100644 index 59f6882140..0000000000 --- a/src/core/getComponentKey.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2013 Facebook, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @providesModule getComponentKey - */ - -"use strict"; - -/** - * Generate a key string that identifies a component within a set. - * - * @param {*} component A component that could contain a manual key. - * @param {number} index Index that is used if a manual key is not provided. - * @return {string} - * @internal - */ -function getComponentKey(component, index) { - if (component && component.props && component.props.key != null) { - // Explicit key - return '{' + component.props.key + '}'; - } - // Implicit key determined by the index in the set - return '[' + index + ']'; -} - -module.exports = getComponentKey; diff --git a/src/core/shouldUpdateReactComponent.js b/src/core/shouldUpdateReactComponent.js index f13373e949..f6edba79b1 100644 --- a/src/core/shouldUpdateReactComponent.js +++ b/src/core/shouldUpdateReactComponent.js @@ -19,8 +19,6 @@ "use strict"; -var getComponentKey = require('getComponentKey'); - /** * Given a `prevComponent` and `nextComponent`, determines if `prevComponent` * should be updated as opposed to being destroyed or replaced. @@ -35,8 +33,8 @@ function shouldUpdateReactComponent(prevComponent, nextComponent) { if (prevComponent && nextComponent && prevComponent.constructor === nextComponent.constructor) { if (prevComponent._owner === nextComponent._owner && ( - getComponentKey(prevComponent, /* index: */ 0) === - getComponentKey(nextComponent, /* index: */ 0) + (prevComponent.props && prevComponent.props.key) === + (nextComponent.props && nextComponent.props.key) )) { return true; } else { diff --git a/src/utils/traverseAllChildren.js b/src/utils/traverseAllChildren.js index 4211f04593..021cbff943 100644 --- a/src/utils/traverseAllChildren.js +++ b/src/utils/traverseAllChildren.js @@ -20,7 +20,6 @@ var ReactTextComponent = require('ReactTextComponent'); -var getComponentKey = require('getComponentKey'); var invariant = require('invariant'); /** @@ -31,6 +30,22 @@ var invariant = require('invariant'); * }); */ +/** + * Generate a key string that identifies a component within a set. + * + * @param {*} component A component that could contain a manual key. + * @param {number} index Index that is used if a manual key is not provided. + * @return {string} + */ +function getComponentKey(component, index) { + if (component && component.props && component.props.key != null) { + // Explicit key + return '{' + component.props.key + '}'; + } + // Implicit key determined by the index in the set + return '[' + index + ']'; +} + /** * @param {?*} children Children tree container. * @param {!string} nameSoFar Name of the key path so far.