Skip to content

Commit ef121b3

Browse files
committed
Refactor
1 parent e2f6f76 commit ef121b3

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const EVENT_KEY = "rn-web-bridge";
2-
export const ROOT_ID = "rnrb-root";
1+
export const TO_WEB_EVENT_KEY = "rn-web-bridge";
2+
export const WEB_ROOT_ID = "rnrb-root";

src/native/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCallback, useRef } from "react";
22
import type WebView from "react-native-webview";
33
import type { WebViewMessageEvent, WebViewProps } from "react-native-webview";
4-
import { EVENT_KEY } from "../constants";
4+
import { TO_WEB_EVENT_KEY } from "../constants";
55
import type { Message } from "../types";
66

77
/**
@@ -10,7 +10,7 @@ import type { Message } from "../types";
1010
export const buildEmitCode = <T>(message: Message<T>): string => {
1111
return `(function() {
1212
try {
13-
window.dispatchEvent(new CustomEvent("${EVENT_KEY}",{detail:${JSON.stringify(
13+
window.dispatchEvent(new CustomEvent("${TO_WEB_EVENT_KEY}",{detail:${JSON.stringify(
1414
message
1515
)}}));
1616
} catch(e) {

src/plugin/html.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ROOT_ID } from "../constants";
1+
import { WEB_ROOT_ID } from "../constants";
22

33
/**
44
* @internal
@@ -21,7 +21,7 @@ const wrapByHtml = (js: string): string => `
2121
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
2222
</head>
2323
<body style="margin: 0 !important;padding: 0 !important;">
24-
<div id="${ROOT_ID}"></div>
24+
<div id="${WEB_ROOT_ID}"></div>
2525
<script type="text/javascript">(function(){${js}})()</script>
2626
</body>
2727
</html>

src/web/core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { EVENT_KEY, ROOT_ID } from "../constants";
1+
import { TO_WEB_EVENT_KEY, WEB_ROOT_ID } from "../constants";
22
import type { Message } from "../types";
33

44
/**
55
* @internal
66
*/
77
export const getWebViewRootElement = (): HTMLElement =>
8-
document.getElementById(ROOT_ID)!;
8+
document.getElementById(WEB_ROOT_ID)!;
99

1010
/**
1111
* A function to send a message to React Native
@@ -24,9 +24,9 @@ export const listenNativeMessage = <T>(
2424
if (!isMessageEvent<T>(e)) return;
2525
onSubscribe({ type: e.detail.type, data: e.detail.data });
2626
};
27-
window.addEventListener(EVENT_KEY, listener);
27+
window.addEventListener(TO_WEB_EVENT_KEY, listener);
2828
return () => {
29-
window.removeEventListener(EVENT_KEY, listener);
29+
window.removeEventListener(TO_WEB_EVENT_KEY, listener);
3030
};
3131
};
3232

0 commit comments

Comments
 (0)