1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | var _prodInvariant = require('./reactProdInvariant');
|
12 |
|
13 | var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
14 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
15 | var ReactInstanceMap = require('./ReactInstanceMap');
|
16 |
|
17 | var getHostComponentFromComposite = require('./getHostComponentFromComposite');
|
18 | var invariant = require('fbjs/lib/invariant');
|
19 | var warning = require('fbjs/lib/warning');
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function findDOMNode(componentOrElement) {
|
30 | if (process.env.NODE_ENV !== 'production') {
|
31 | var owner = ReactCurrentOwner.current;
|
32 | if (owner !== null) {
|
33 | process.env.NODE_ENV !== 'production' ? warning(owner._warnedAboutRefsInRender, '%s is accessing findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', owner.getName() || 'A component') : void 0;
|
34 | owner._warnedAboutRefsInRender = true;
|
35 | }
|
36 | }
|
37 | if (componentOrElement == null) {
|
38 | return null;
|
39 | }
|
40 | if (componentOrElement.nodeType === 1) {
|
41 | return componentOrElement;
|
42 | }
|
43 |
|
44 | var inst = ReactInstanceMap.get(componentOrElement);
|
45 | if (inst) {
|
46 | inst = getHostComponentFromComposite(inst);
|
47 | return inst ? ReactDOMComponentTree.getNodeFromInstance(inst) : null;
|
48 | }
|
49 |
|
50 | if (typeof componentOrElement.render === 'function') {
|
51 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'findDOMNode was called on an unmounted component.') : _prodInvariant('44') : void 0;
|
52 | } else {
|
53 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element appears to be neither ReactComponent nor DOMNode (keys: %s)', Object.keys(componentOrElement)) : _prodInvariant('45', Object.keys(componentOrElement)) : void 0;
|
54 | }
|
55 | }
|
56 |
|
57 | module.exports = findDOMNode; |
\ | No newline at end of file |