Skip to content

Commit

Permalink
fix: store mocking on not native env (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
gronxb authored Jul 3, 2024
1 parent 94e0174 commit 6ff6aa7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/web/src/internal/bridgeInstance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
Bridge,
BridgeStore,
ExcludePrimitive,
ExtractStore,
KeyOfOrString,
Parser,
Expand All @@ -11,6 +12,7 @@ import {
createRandomId,
createResolver,
DefaultEmitter,
noop,
timeout,
} from "@webview-bridge/util";

Expand All @@ -36,9 +38,14 @@ export class BridgeInstance<

private defaultTimeoutMs = 2000;

public store: Omit<T, "setState"> = {} as Omit<T, "setState">;
public store: Omit<T, "setState"> = {
getState: () => ({}) as ExcludePrimitive<ExtractStore<T>>,
subscribe: noop,
} as unknown as Omit<T, "setState">;

public isWebViewBridgeAvailable = Boolean(window.ReactNativeWebView);
get isWebViewBridgeAvailable() {
return Boolean(window.ReactNativeWebView) && this._bridgeMethods.length > 0;
}

public isNativeMethodAvailable(methodName: string) {
return (
Expand Down Expand Up @@ -180,8 +187,6 @@ export class BridgeInstance<
initialState,
nativeInitialState as ExtractStore<T>,
);
this.isWebViewBridgeAvailable =
Boolean(window.ReactNativeWebView) && bridgeMethods.length > 0;

document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") {
Expand Down

0 comments on commit 6ff6aa7

Please sign in to comment.