-
Notifications
You must be signed in to change notification settings - Fork 24.2k
/
JSDevSupport.java
70 lines (55 loc) · 1.97 KB
/
JSDevSupport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react.devsupport;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.module.annotations.ReactModule;
import javax.annotation.Nullable;
@ReactModule(name = "JSDevSupport", needsEagerInit = true)
public class JSDevSupport extends ReactContextBaseJavaModule {
static final String MODULE_NAME = "JSDevSupport";
@Nullable
private volatile DevSupportCallback mCurrentCallback = null;
public interface JSDevSupportModule extends JavaScriptModule {
void getJSHierarchy(String reactTag);
}
public JSDevSupport(ReactApplicationContext reactContext) {
super(reactContext);
}
public interface DevSupportCallback {
void onSuccess(String data);
void onFailure(Exception error);
}
public synchronized void getJSHierarchy(String reactTag, DevSupportCallback callback) {
if (mCurrentCallback != null) {
callback.onFailure(new RuntimeException("JS Hierarchy download already in progress."));
return;
}
JSDevSupportModule
jsDevSupportModule = getReactApplicationContext().getJSModule(JSDevSupportModule.class);
if (jsDevSupportModule == null) {
callback.onFailure(new JSCHeapCapture.CaptureException(MODULE_NAME +
" module not registered."));
return;
}
mCurrentCallback = callback;
jsDevSupportModule.getJSHierarchy(reactTag);
}
@SuppressWarnings("unused")
@ReactMethod
public synchronized void setResult(String data, String error) {
if (mCurrentCallback != null) {
if (error == null) {
mCurrentCallback.onSuccess(data);
} else {
mCurrentCallback.onFailure(new RuntimeException(error));
}
}
mCurrentCallback = null;
}
@Override
public String getName() {
return "JSDevSupport";
}
}