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

Add setter for the ID_ATTRIBUTE_NAME to top-level React #4668

Closed
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
4 changes: 4 additions & 0 deletions src/browser/ui/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var ReactDOM = require('ReactDOM');
var ReactDOMTextComponent = require('ReactDOMTextComponent');
var ReactDefaultInjection = require('ReactDefaultInjection');
var ReactInstanceHandles = require('ReactInstanceHandles');
var DOMProperty = require('DOMProperty');
var ReactMount = require('ReactMount');
var ReactPerf = require('ReactPerf');
var ReactPropTypes = require('ReactPropTypes');
Expand All @@ -50,6 +51,9 @@ if (__DEV__) {
var render = ReactPerf.measure('React', 'render', ReactMount.render);

var React = {
setIdAttributeName: function(id) {
DOMProperty.ID_ATTRIBUTE_NAME = id;
},
Children: {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
Expand Down
9 changes: 4 additions & 5 deletions src/browser/ui/ReactMount.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var warning = require('warning');

var SEPARATOR = ReactInstanceHandles.SEPARATOR;

var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
var nodeCache = {};

var ELEMENT_NODE_TYPE = 1;
Expand Down Expand Up @@ -100,7 +99,7 @@ function getID(node) {
invariant(
!isValid(cached, id),
'ReactMount: Two valid but unequal nodes with the same `%s`: %s',
ATTR_NAME, id
DOMProperty.ID_ATTRIBUTE_NAME, id
);

nodeCache[id] = node;
Expand All @@ -117,7 +116,7 @@ function internalGetID(node) {
// If node is something like a window, document, or text node, none of
// which support attributes or a .getAttribute method, gracefully return
// the empty string, as if the attribute were missing.
return node && node.getAttribute && node.getAttribute(ATTR_NAME) || '';
return node && node.getAttribute && node.getAttribute(DOMProperty.ID_ATTRIBUTE_NAME) || '';
}

/**
Expand All @@ -131,7 +130,7 @@ function setID(node, id) {
if (oldID !== id) {
delete nodeCache[oldID];
}
node.setAttribute(ATTR_NAME, id);
node.setAttribute(DOMProperty.ID_ATTRIBUTE_NAME, id);
nodeCache[id] = node;
}

Expand Down Expand Up @@ -182,7 +181,7 @@ function isValid(node, id) {
invariant(
internalGetID(node) === id,
'ReactMount: Unexpected modification of `%s`',
ATTR_NAME
DOMProperty.ID_ATTRIBUTE_NAME
);

var container = ReactMount.findReactContainerForID(id);
Expand Down