Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move repeated code to removeAllChildren #2339

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/browser/ui/ReactMount.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var containsNode = require('containsNode');
var getReactRootElementInContainer = require('getReactRootElementInContainer');
var instantiateReactComponent = require('instantiateReactComponent');
var invariant = require('invariant');
var removeAllChildren = require('removeAllChildren');
var setInnerHTML = require('setInnerHTML');
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
var warning = require('warning');
Expand Down Expand Up @@ -612,10 +613,7 @@ var ReactMount = {
container = container.documentElement;
}

// http://jsperf.com/emptying-a-node
while (container.lastChild) {
container.removeChild(container.lastChild);
}
removeAllChildren(container);
},

/**
Expand Down
25 changes: 25 additions & 0 deletions src/browser/ui/dom/removeAllChildren.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule removeAllChildren
*/

'use strict';

/**
* @param {DOMElement} node
*/
function removeAllChildren(node) {
// http://jsperf.com/emptying-a-node
var firstChild;
while ((firstChild = node.firstChild)) {
node.removeChild(firstChild);
}
}

module.exports = removeAllChildren;
5 changes: 2 additions & 3 deletions src/vendor/core/createNodesFromMarkup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var ExecutionEnvironment = require('ExecutionEnvironment');
var createArrayFrom = require('createArrayFrom');
var getMarkupWrap = require('getMarkupWrap');
var invariant = require('invariant');
var removeAllChildren = require('removeAllChildren');

/**
* Dummy container used to render all markup.
Expand Down Expand Up @@ -77,9 +78,7 @@ function createNodesFromMarkup(markup, handleScript) {
}

var nodes = createArrayFrom(node.childNodes);
while (node.lastChild) {
node.removeChild(node.lastChild);
}
removeAllChildren(node);
return nodes;
}

Expand Down