-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inject react-art renderer into react-devtools
- Loading branch information
1 parent
5662595
commit a4b4b62
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {HostComponent, HostText} from 'shared/ReactTypeOfWork'; | ||
|
||
const randomKey = Math.random() | ||
.toString(36) | ||
.slice(2); | ||
const internalInstanceKey = '__reactInternalInstance$' + randomKey; | ||
|
||
export function precacheFiberNode(hostInst, node) { | ||
node[internalInstanceKey] = hostInst; | ||
} | ||
|
||
export function getClosestInstanceFromNode(node) { | ||
if (node[internalInstanceKey]) { | ||
return node[internalInstanceKey]; | ||
} | ||
|
||
while (!node[internalInstanceKey]) { | ||
if (node.parentNode) { | ||
node = node.parentNode; | ||
} else { | ||
// Top of the tree. This node must not be part of a React tree (or is | ||
// unmounted, potentially). | ||
return null; | ||
} | ||
} | ||
|
||
let inst = node[internalInstanceKey]; | ||
if (inst.tag === HostComponent || inst.tag === HostText) { | ||
// In Fiber, this will always be the deepest root. | ||
return inst; | ||
} | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters