Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: linkBridge debug mode #90

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/shared-state-integration-react/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { AppBridge } from "@webview-bridge-example-shared-state-integration

const bridge = linkBridge<AppBridge>({
throwOnError: true,
debug: true,
initialBridge: {
count: 10,
data: {
Expand Down
16 changes: 12 additions & 4 deletions packages/web/src/linkBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface LinkBridgeOptions<
T extends BridgeStore<T extends Bridge ? T : any>,
V extends ParserSchema<any>,
> {
/**
* If `true`, console warnings will be displayed.
* @default false
*/
debug?: boolean;
/**
* It is possible to configure `initialBridge` to operate in a non-React Native environment.
* Prioritize applying the bridge of the React Native WebView, and if it is unavailable, apply the `initialBridge`.
Expand Down Expand Up @@ -65,6 +70,7 @@ export const linkBridge = <
options: LinkBridgeOptions<T, V> = {
timeout: 2000,
throwOnError: false,
debug: false,
},
): LinkBridge<ExcludePrimitive<ExtractStore<T>>, Omit<T, "setState">, V> => {
if (typeof window === "undefined") {
Expand All @@ -88,7 +94,7 @@ export const linkBridge = <
} as LinkBridge<ExcludePrimitive<ExtractStore<T>>, Omit<T, "setState">, V>;
}

if (!window.ReactNativeWebView) {
if (options.debug && !window.ReactNativeWebView) {
console.warn("[WebViewBridge] Not in a WebView environment");
}

Expand Down Expand Up @@ -147,9 +153,11 @@ export const linkBridge = <
};
}

console.warn(
`[WebViewBridge] ${methodName} is not defined, using fallback.`,
);
if (options.debug) {
console.warn(
`[WebViewBridge] ${methodName} is not defined, using fallback.`,
);
}
return () => Promise.resolve();
},
}) as LinkBridge<ExcludePrimitive<ExtractStore<T>>, Omit<T, "setState">, V>;
Expand Down
Loading