コード例 #1
0
ファイル: ReactID.js プロジェクト: danthamotheram/react
/**
 * Finds the node with the supplied React-generated DOM ID.
 *
 * @param {string} id A React-generated DOM ID.
 * @return {?DOMElement} DOM node with the suppled `id`.
 * @internal
 */
function getNode(id) {
  if (!nodeCache.hasOwnProperty(id)) {
    nodeCache[id] =
      document.getElementById(id) || // TODO Quit using getElementById.
      ReactMount.findReactRenderedDOMNodeSlow(id);
  }

  var node = nodeCache[id];
  if (getID(node) === id) {
    return node;
  }

  return null;
}
コード例 #2
0
ファイル: ReactComponent.js プロジェクト: kuguobing/react
 getDOMNode: function() {
   invariant(
     ExecutionEnvironment.canUseDOM,
     'getDOMNode(): The DOM is not supported in the current environment.'
   );
   invariant(
     this._lifeCycleState === ComponentLifeCycle.MOUNTED,
     'getDOMNode(): A component must be mounted to have a DOM node.'
   );
   var rootNode = this._rootNode;
   if (!rootNode) {
     rootNode = document.getElementById(this._rootNodeID);
     if (!rootNode) {
       // TODO: Log the frequency that we reach this path.
       rootNode = ReactMount.findReactRenderedDOMNodeSlow(this._rootNodeID);
     }
     this._rootNode = rootNode;
   }
   return rootNode;
 },
コード例 #3
0
 getCachedNodeByID: function(id) {
   return nodeCache[id] ||
     (nodeCache[id] =
       document.getElementById(id) ||
       ReactMount.findReactRenderedDOMNodeSlow(id));
 }