1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var _prodInvariant = require('./reactProdInvariant');
|
14 |
|
15 | var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
16 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
17 | var ReactInstanceMap = require('./ReactInstanceMap');
|
18 |
|
19 | var getHostComponentFromComposite = require('./getHostComponentFromComposite');
|
20 | var invariant = require('fbjs/lib/invariant');
|
21 | var warning = require('fbjs/lib/warning');
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function findDOMNode(componentOrElement) {
|
32 | if (process.env.NODE_ENV !== 'production') {
|
33 | var owner = ReactCurrentOwner.current;
|
34 | if (owner !== null) {
|
35 | 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;
|
36 | owner._warnedAboutRefsInRender = true;
|
37 | }
|
38 | }
|
39 | if (componentOrElement == null) {
|
40 | return null;
|
41 | }
|
42 | if (componentOrElement.nodeType === 1) {
|
43 | return componentOrElement;
|
44 | }
|
45 |
|
46 | var inst = ReactInstanceMap.get(componentOrElement);
|
47 | if (inst) {
|
48 | inst = getHostComponentFromComposite(inst);
|
49 | return inst ? ReactDOMComponentTree.getNodeFromInstance(inst) : null;
|
50 | }
|
51 |
|
52 | if (typeof componentOrElement.render === 'function') {
|
53 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'findDOMNode was called on an unmounted component.') : _prodInvariant('44') : void 0;
|
54 | } else {
|
55 | !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;
|
56 | }
|
57 | }
|
58 |
|
59 | module.exports = findDOMNode; |
\ | No newline at end of file |