@webview-bridge/react-native 1.7.8 → 1.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +43 -21
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +44 -22
- package/package.json +6 -9
- package/src/error.ts +14 -0
- package/src/integrations/bridge.ts +17 -7
- package/src/useBridge.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -103,6 +103,13 @@ function _inherits(subClass, superClass) {
|
|
|
103
103
|
});
|
|
104
104
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
105
105
|
}
|
|
106
|
+
function _instanceof(left, right) {
|
|
107
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
108
|
+
return !!right[Symbol.hasInstance](left);
|
|
109
|
+
} else {
|
|
110
|
+
return left instanceof right;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
106
113
|
function _is_native_function(fn) {
|
|
107
114
|
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
108
115
|
}
|
|
@@ -440,6 +447,34 @@ var import_react = require("react");
|
|
|
440
447
|
var import_react_native_webview = __toESM(require("react-native-webview"), 1);
|
|
441
448
|
// src/integrations/bridge.ts
|
|
442
449
|
var import_utils = require("@webview-bridge/utils");
|
|
450
|
+
// src/error.ts
|
|
451
|
+
var WebMethodError = /*#__PURE__*/ function(Error1) {
|
|
452
|
+
_inherits(WebMethodError, Error1);
|
|
453
|
+
function WebMethodError(methodName) {
|
|
454
|
+
_class_call_check(this, WebMethodError);
|
|
455
|
+
var _this;
|
|
456
|
+
_this = _call_super(this, WebMethodError, [
|
|
457
|
+
"An error occurred in the WebMethod.current.".concat(methodName)
|
|
458
|
+
]);
|
|
459
|
+
_this.name = "WebMethodError";
|
|
460
|
+
return _this;
|
|
461
|
+
}
|
|
462
|
+
return WebMethodError;
|
|
463
|
+
}(_wrap_native_super(Error));
|
|
464
|
+
function serializeError(error) {
|
|
465
|
+
return JSON.stringify(error, function(_, value) {
|
|
466
|
+
if (_instanceof(value, Error)) {
|
|
467
|
+
return {
|
|
468
|
+
name: value.name,
|
|
469
|
+
message: value.message,
|
|
470
|
+
stack: value.stack,
|
|
471
|
+
__isError: true
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
return value;
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
// src/integrations/bridge.ts
|
|
443
478
|
var bridge = function(procedures) {
|
|
444
479
|
var getState = function() {
|
|
445
480
|
return state;
|
|
@@ -501,8 +536,9 @@ var handleBridge = /*#__PURE__*/ function() {
|
|
|
501
536
|
bridge2 = param.bridge, method = param.method, args = param.args, webview = param.webview, eventId = param.eventId, bridgeId = param.bridgeId;
|
|
502
537
|
_bridge = bridge2.getState();
|
|
503
538
|
_method = _bridge[method];
|
|
504
|
-
handleThrow = function() {
|
|
505
|
-
|
|
539
|
+
handleThrow = function(error) {
|
|
540
|
+
var serializedError = error ? serializeError(error) : true;
|
|
541
|
+
webview.injectJavaScript(SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID(bridgeId, "".concat(method, "-").concat(eventId), serializedError));
|
|
506
542
|
};
|
|
507
543
|
if (!(method in _bridge)) {
|
|
508
544
|
handleThrow();
|
|
@@ -536,7 +572,7 @@ var handleBridge = /*#__PURE__*/ function() {
|
|
|
536
572
|
];
|
|
537
573
|
case 3:
|
|
538
574
|
error = _state.sent();
|
|
539
|
-
handleThrow();
|
|
575
|
+
handleThrow(_instanceof(error, Error) ? error : new Error(String(error)));
|
|
540
576
|
console.error(error);
|
|
541
577
|
return [
|
|
542
578
|
3,
|
|
@@ -567,8 +603,9 @@ var SAFE_NATIVE_EMITTER_EMIT_BY_BRIDGE_ID = function(bridgeId, eventName, data)
|
|
|
567
603
|
var dataString = JSON.stringify(data);
|
|
568
604
|
return "\n (function() {\n if (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', ").concat(dataString, ");\n } else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', ").concat(dataString, ");\n } else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n }\n return true;\n })();\n");
|
|
569
605
|
};
|
|
570
|
-
var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName) {
|
|
571
|
-
|
|
606
|
+
var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName, serializedError) {
|
|
607
|
+
var serializedErrorString = JSON.stringify(serializedError);
|
|
608
|
+
return "\n (function() {\n if (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', {}, ").concat(serializedErrorString, ");\n } else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', {}, ").concat(serializedErrorString, ");\n } else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', {}, ").concat(serializedErrorString, "]);\n }\n return true;\n })();\n");
|
|
572
609
|
};
|
|
573
610
|
// src/integrations/console.ts
|
|
574
611
|
var INJECT_DEBUG = function(uniqueId) {
|
|
@@ -606,21 +643,6 @@ var handleLog = function(type, message) {
|
|
|
606
643
|
};
|
|
607
644
|
// src/integrations/handleRegisterWebMethod.ts
|
|
608
645
|
var import_utils2 = require("@webview-bridge/utils");
|
|
609
|
-
// src/error.ts
|
|
610
|
-
var WebMethodError = /*#__PURE__*/ function(Error1) {
|
|
611
|
-
_inherits(WebMethodError, Error1);
|
|
612
|
-
function WebMethodError(methodName) {
|
|
613
|
-
_class_call_check(this, WebMethodError);
|
|
614
|
-
var _this;
|
|
615
|
-
_this = _call_super(this, WebMethodError, [
|
|
616
|
-
"An error occurred in the WebMethod.current.".concat(methodName)
|
|
617
|
-
]);
|
|
618
|
-
_this.name = "WebMethodError";
|
|
619
|
-
return _this;
|
|
620
|
-
}
|
|
621
|
-
return WebMethodError;
|
|
622
|
-
}(_wrap_native_super(Error));
|
|
623
|
-
// src/integrations/handleRegisterWebMethod.ts
|
|
624
646
|
var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTimeout) {
|
|
625
647
|
return bridgeNames.reduce(function(acc, methodName) {
|
|
626
648
|
acc[methodName] = /*#__PURE__*/ _async_to_generator(function() {
|
|
@@ -922,7 +944,7 @@ var postMessageSchema = function(schema) {
|
|
|
922
944
|
return schema;
|
|
923
945
|
};
|
|
924
946
|
// src/useBridge.ts
|
|
925
|
-
var import_with_selector = require("use-sync-external-store/with-selector
|
|
947
|
+
var import_with_selector = require("use-sync-external-store/with-selector");
|
|
926
948
|
function useBridge(store, selector) {
|
|
927
949
|
var $selector = selector !== null && selector !== void 0 ? selector : function(state) {
|
|
928
950
|
return state;
|
package/dist/index.d.cts
CHANGED
|
@@ -153,7 +153,7 @@ declare const INJECT_BRIDGE_METHODS: (bridgeNames: string[]) => string;
|
|
|
153
153
|
declare const INJECT_BRIDGE_STATE: (initialState: Record<string, Primitive>) => string;
|
|
154
154
|
declare const SAFE_NATIVE_EMITTER_EMIT: (eventName: string, data: unknown) => string;
|
|
155
155
|
declare const SAFE_NATIVE_EMITTER_EMIT_BY_BRIDGE_ID: (bridgeId: string, eventName: string, data: unknown) => string;
|
|
156
|
-
declare const SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID: (bridgeId: string, eventName: string) => string;
|
|
156
|
+
declare const SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID: (bridgeId: string, eventName: string, serializedError: string | true) => string;
|
|
157
157
|
|
|
158
158
|
declare const postMessageSchema: <T extends PostMessageSchemaObject>(schema: T) => T;
|
|
159
159
|
|
package/dist/index.d.ts
CHANGED
|
@@ -153,7 +153,7 @@ declare const INJECT_BRIDGE_METHODS: (bridgeNames: string[]) => string;
|
|
|
153
153
|
declare const INJECT_BRIDGE_STATE: (initialState: Record<string, Primitive>) => string;
|
|
154
154
|
declare const SAFE_NATIVE_EMITTER_EMIT: (eventName: string, data: unknown) => string;
|
|
155
155
|
declare const SAFE_NATIVE_EMITTER_EMIT_BY_BRIDGE_ID: (bridgeId: string, eventName: string, data: unknown) => string;
|
|
156
|
-
declare const SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID: (bridgeId: string, eventName: string) => string;
|
|
156
|
+
declare const SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID: (bridgeId: string, eventName: string, serializedError: string | true) => string;
|
|
157
157
|
|
|
158
158
|
declare const postMessageSchema: <T extends PostMessageSchemaObject>(schema: T) => T;
|
|
159
159
|
|
package/dist/index.js
CHANGED
|
@@ -103,6 +103,13 @@ function _inherits(subClass, superClass) {
|
|
|
103
103
|
});
|
|
104
104
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
105
105
|
}
|
|
106
|
+
function _instanceof(left, right) {
|
|
107
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
108
|
+
return !!right[Symbol.hasInstance](left);
|
|
109
|
+
} else {
|
|
110
|
+
return left instanceof right;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
106
113
|
function _is_native_function(fn) {
|
|
107
114
|
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
108
115
|
}
|
|
@@ -346,6 +353,35 @@ import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useMemo, u
|
|
|
346
353
|
import WebView from "react-native-webview";
|
|
347
354
|
// src/integrations/bridge.ts
|
|
348
355
|
import { equals, removeUndefinedKeys } from "@webview-bridge/utils";
|
|
356
|
+
// src/error.ts
|
|
357
|
+
var WebMethodError = /*#__PURE__*/ function(Error1) {
|
|
358
|
+
"use strict";
|
|
359
|
+
_inherits(WebMethodError, Error1);
|
|
360
|
+
function WebMethodError(methodName) {
|
|
361
|
+
_class_call_check(this, WebMethodError);
|
|
362
|
+
var _this;
|
|
363
|
+
_this = _call_super(this, WebMethodError, [
|
|
364
|
+
"An error occurred in the WebMethod.current.".concat(methodName)
|
|
365
|
+
]);
|
|
366
|
+
_this.name = "WebMethodError";
|
|
367
|
+
return _this;
|
|
368
|
+
}
|
|
369
|
+
return WebMethodError;
|
|
370
|
+
}(_wrap_native_super(Error));
|
|
371
|
+
function serializeError(error) {
|
|
372
|
+
return JSON.stringify(error, function(_, value) {
|
|
373
|
+
if (_instanceof(value, Error)) {
|
|
374
|
+
return {
|
|
375
|
+
name: value.name,
|
|
376
|
+
message: value.message,
|
|
377
|
+
stack: value.stack,
|
|
378
|
+
__isError: true
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
return value;
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
// src/integrations/bridge.ts
|
|
349
385
|
var bridge = function(procedures) {
|
|
350
386
|
var getState = function() {
|
|
351
387
|
return state;
|
|
@@ -407,8 +443,9 @@ var handleBridge = /*#__PURE__*/ function() {
|
|
|
407
443
|
bridge2 = param.bridge, method = param.method, args = param.args, webview = param.webview, eventId = param.eventId, bridgeId = param.bridgeId;
|
|
408
444
|
_bridge = bridge2.getState();
|
|
409
445
|
_method = _bridge[method];
|
|
410
|
-
handleThrow = function() {
|
|
411
|
-
|
|
446
|
+
handleThrow = function(error) {
|
|
447
|
+
var serializedError = error ? serializeError(error) : true;
|
|
448
|
+
webview.injectJavaScript(SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID(bridgeId, "".concat(method, "-").concat(eventId), serializedError));
|
|
412
449
|
};
|
|
413
450
|
if (!(method in _bridge)) {
|
|
414
451
|
handleThrow();
|
|
@@ -442,7 +479,7 @@ var handleBridge = /*#__PURE__*/ function() {
|
|
|
442
479
|
];
|
|
443
480
|
case 3:
|
|
444
481
|
error = _state.sent();
|
|
445
|
-
handleThrow();
|
|
482
|
+
handleThrow(_instanceof(error, Error) ? error : new Error(String(error)));
|
|
446
483
|
console.error(error);
|
|
447
484
|
return [
|
|
448
485
|
3,
|
|
@@ -473,8 +510,9 @@ var SAFE_NATIVE_EMITTER_EMIT_BY_BRIDGE_ID = function(bridgeId, eventName, data)
|
|
|
473
510
|
var dataString = JSON.stringify(data);
|
|
474
511
|
return "\n (function() {\n if (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', ").concat(dataString, ");\n } else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', ").concat(dataString, ");\n } else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', ").concat(dataString, "]);\n }\n return true;\n })();\n");
|
|
475
512
|
};
|
|
476
|
-
var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName) {
|
|
477
|
-
|
|
513
|
+
var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName, serializedError) {
|
|
514
|
+
var serializedErrorString = JSON.stringify(serializedError);
|
|
515
|
+
return "\n (function() {\n if (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', {}, ").concat(serializedErrorString, ");\n } else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', {}, ").concat(serializedErrorString, ");\n } else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', {}, ").concat(serializedErrorString, "]);\n }\n return true;\n })();\n");
|
|
478
516
|
};
|
|
479
517
|
// src/integrations/console.ts
|
|
480
518
|
var INJECT_DEBUG = function(uniqueId) {
|
|
@@ -512,22 +550,6 @@ var handleLog = function(type, message) {
|
|
|
512
550
|
};
|
|
513
551
|
// src/integrations/handleRegisterWebMethod.ts
|
|
514
552
|
import { createRandomId, createResolver, timeout } from "@webview-bridge/utils";
|
|
515
|
-
// src/error.ts
|
|
516
|
-
var WebMethodError = /*#__PURE__*/ function(Error1) {
|
|
517
|
-
"use strict";
|
|
518
|
-
_inherits(WebMethodError, Error1);
|
|
519
|
-
function WebMethodError(methodName) {
|
|
520
|
-
_class_call_check(this, WebMethodError);
|
|
521
|
-
var _this;
|
|
522
|
-
_this = _call_super(this, WebMethodError, [
|
|
523
|
-
"An error occurred in the WebMethod.current.".concat(methodName)
|
|
524
|
-
]);
|
|
525
|
-
_this.name = "WebMethodError";
|
|
526
|
-
return _this;
|
|
527
|
-
}
|
|
528
|
-
return WebMethodError;
|
|
529
|
-
}(_wrap_native_super(Error));
|
|
530
|
-
// src/integrations/handleRegisterWebMethod.ts
|
|
531
553
|
var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTimeout) {
|
|
532
554
|
return bridgeNames.reduce(function(acc, methodName) {
|
|
533
555
|
acc[methodName] = /*#__PURE__*/ _async_to_generator(function() {
|
|
@@ -829,7 +851,7 @@ var postMessageSchema = function(schema) {
|
|
|
829
851
|
return schema;
|
|
830
852
|
};
|
|
831
853
|
// src/useBridge.ts
|
|
832
|
-
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector
|
|
854
|
+
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
|
|
833
855
|
function useBridge(store, selector) {
|
|
834
856
|
var $selector = selector !== null && selector !== void 0 ? selector : function(state) {
|
|
835
857
|
return state;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webview-bridge/react-native",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fully Type-Safe Integration for React Native WebView and Web",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
|
-
"repository":
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "https://github.com/gronxb/webview-bridge.git"
|
|
23
|
-
},
|
|
20
|
+
"repository": "https://github.com/gronxb/webview-bridge",
|
|
24
21
|
"license": "MIT",
|
|
25
22
|
"files": [
|
|
26
23
|
"dist",
|
|
@@ -29,7 +26,7 @@
|
|
|
29
26
|
],
|
|
30
27
|
"devDependencies": {
|
|
31
28
|
"@types/react": "^18.2.25",
|
|
32
|
-
"@types/use-sync-external-store": "^
|
|
29
|
+
"@types/use-sync-external-store": "^1.5.0",
|
|
33
30
|
"react": "^18.3.1",
|
|
34
31
|
"react-native-webview": "^13.12.0",
|
|
35
32
|
"typescript": "^5.6.2"
|
|
@@ -39,9 +36,9 @@
|
|
|
39
36
|
"react-native-webview": "*"
|
|
40
37
|
},
|
|
41
38
|
"dependencies": {
|
|
42
|
-
"
|
|
43
|
-
"@webview-bridge/types": "1.7.
|
|
44
|
-
"
|
|
39
|
+
"use-sync-external-store": "1.6.0",
|
|
40
|
+
"@webview-bridge/types": "1.7.9",
|
|
41
|
+
"@webview-bridge/utils": "1.7.9"
|
|
45
42
|
},
|
|
46
43
|
"scripts": {
|
|
47
44
|
"build": "tsup --config ./tsup.config.ts",
|
package/src/error.ts
CHANGED
|
@@ -4,3 +4,17 @@ export class WebMethodError extends Error {
|
|
|
4
4
|
this.name = "WebMethodError";
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
export function serializeError(error: Error) {
|
|
9
|
+
return JSON.stringify(error, (_, value) => {
|
|
10
|
+
if (value instanceof Error) {
|
|
11
|
+
return {
|
|
12
|
+
name: value.name,
|
|
13
|
+
message: value.message,
|
|
14
|
+
stack: value.stack,
|
|
15
|
+
__isError: true,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from "@webview-bridge/types";
|
|
7
7
|
import { equals, removeUndefinedKeys } from "@webview-bridge/utils";
|
|
8
8
|
import type WebView from "react-native-webview";
|
|
9
|
+
import { serializeError } from "../error";
|
|
9
10
|
|
|
10
11
|
export type StoreCallback<T> = ({
|
|
11
12
|
get,
|
|
@@ -83,9 +84,14 @@ export const handleBridge = async ({
|
|
|
83
84
|
const _bridge = bridge.getState();
|
|
84
85
|
|
|
85
86
|
const _method = _bridge[method];
|
|
86
|
-
const handleThrow = () => {
|
|
87
|
+
const handleThrow = (error?: Error) => {
|
|
88
|
+
const serializedError = error ? serializeError(error) : true;
|
|
87
89
|
webview.injectJavaScript(
|
|
88
|
-
SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID(
|
|
90
|
+
SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID(
|
|
91
|
+
bridgeId,
|
|
92
|
+
`${method}-${eventId}`,
|
|
93
|
+
serializedError,
|
|
94
|
+
),
|
|
89
95
|
);
|
|
90
96
|
};
|
|
91
97
|
if (!(method in _bridge)) {
|
|
@@ -107,7 +113,7 @@ export const handleBridge = async ({
|
|
|
107
113
|
),
|
|
108
114
|
);
|
|
109
115
|
} catch (error) {
|
|
110
|
-
handleThrow();
|
|
116
|
+
handleThrow(error instanceof Error ? error : new Error(String(error)));
|
|
111
117
|
console.error(error);
|
|
112
118
|
}
|
|
113
119
|
};
|
|
@@ -171,17 +177,21 @@ export const SAFE_NATIVE_EMITTER_EMIT_BY_BRIDGE_ID = (
|
|
|
171
177
|
export const SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = (
|
|
172
178
|
bridgeId: string,
|
|
173
179
|
eventName: string,
|
|
174
|
-
|
|
180
|
+
serializedError: string | true,
|
|
181
|
+
) => {
|
|
182
|
+
const serializedErrorString = JSON.stringify(serializedError);
|
|
183
|
+
return `
|
|
175
184
|
(function() {
|
|
176
185
|
if (window.nativeEmitterMap && window.nativeEmitterMap['${bridgeId}']) {
|
|
177
|
-
window.nativeEmitterMap['${bridgeId}'].emit('${eventName}', {},
|
|
186
|
+
window.nativeEmitterMap['${bridgeId}'].emit('${eventName}', {}, ${serializedErrorString});
|
|
178
187
|
} else if (window.nativeEmitter) {
|
|
179
188
|
// @deprecated This version is not used after 1.7.2
|
|
180
|
-
window.nativeEmitter.emit('${eventName}', {},
|
|
189
|
+
window.nativeEmitter.emit('${eventName}', {}, ${serializedErrorString});
|
|
181
190
|
} else {
|
|
182
191
|
window.nativeBatchedEvents = window.nativeBatchedEvents || [];
|
|
183
|
-
window.nativeBatchedEvents.push(['${eventName}', {},
|
|
192
|
+
window.nativeBatchedEvents.push(['${eventName}', {}, ${serializedErrorString}]);
|
|
184
193
|
}
|
|
185
194
|
return true;
|
|
186
195
|
})();
|
|
187
196
|
`;
|
|
197
|
+
};
|
package/src/useBridge.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Bridge, BridgeStore, ExtractStore } from "@webview-bridge/types";
|
|
2
|
-
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector
|
|
2
|
+
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
|
|
3
3
|
|
|
4
4
|
export function useBridge<T extends Bridge>(
|
|
5
5
|
store: BridgeStore<T>,
|