Created
April 18, 2017 20:33
-
-
Save aleclarson/5cc764ee62716a98cc980a4585f28bf0 to your computer and use it in GitHub Desktop.
React debug utils
This file contains hidden or 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
global.getParentView = do -> | |
ReactInstanceMap = require "ReactInstanceMap" | |
return (view, level = 1) -> | |
unless view._reactInternalInstance | |
view = view._currentElement._owner._instance | |
parent = ReactInstanceMap.get view | |
while parent and --level >= 0 | |
parent = parent._currentElement._owner | |
if parent | |
then parent._instance | |
else null | |
global.getParentInstance = do -> | |
isNode = require "fbjs/lib/isNode" | |
EventPluginUtils = require "react-native/lib/EventPluginUtils" | |
getRenderedComponent = (inst) -> | |
inst._reactInternalInstance._renderedComponent | |
getInstanceFromHost = (host) -> | |
host._currentElement._owner._instance | |
return (inst, level = 1) -> | |
if isNode inst | |
node = EventPluginUtils.getInstanceFromNode inst | |
inst = getInstanceFromHost node | |
else | |
node = getRenderedComponent inst | |
if level is 0 | |
return inst | |
parent = node | |
while parent and --level >= 0 | |
parent = EventPluginUtils.getParentInstance parent | |
return null unless parent | |
parentInst = getInstanceFromHost parent | |
if inst is parentInst | |
then null | |
else parentInst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment