@hylid/call
Advanced tools
Comparing version 4.0.0-alpha.18 to 4.0.0-alpha.19
@@ -27,5 +27,4 @@ var _a; | ||
} | ||
; | ||
export { WebViewBridge } from "./webviewBridge"; | ||
export { mpCall, mpWebCall, webCall, notFound, mpWebCallAsync, webCallAsync }; | ||
export { promisify } from "./promisify"; |
@@ -141,9 +141,39 @@ var __assign = this && this.__assign || function () { | ||
var messageHandler = function messageHandler(message) { | ||
var _a; | ||
var serialId = message.serialId; | ||
if (!serialId) return; | ||
if (!callMap[serialId]) return; | ||
var callback = callMap[serialId]; | ||
var data = message.result; | ||
if (serialId) { | ||
var callback = callMap[serialId]; | ||
callbackFn(data, callback); | ||
delete callMap[serialId]; | ||
var type = (_a = message.config) === null || _a === void 0 ? void 0 : _a.type; | ||
if (type === 'callback') { | ||
var _b = data || {}, | ||
_data_2 = _b._data_, | ||
_type_2 = _b._type_; | ||
if (_type_2 === 'success') return callback(_data_2); | ||
return callback(undefined, _data_2); | ||
} | ||
var _c = callback || {}, | ||
success = _c.success, | ||
fail = _c.fail, | ||
complete = _c.complete; | ||
var _d = data || {}, | ||
_data_ = _d._data_, | ||
_type_ = _d._type_; | ||
// 新版本协议 | ||
if (_type_) { | ||
if (_type_ === 'success') success === null || success === void 0 ? void 0 : success(_data_); | ||
if (_type_ === 'fail') fail === null || fail === void 0 ? void 0 : fail(_data_); | ||
complete === null || complete === void 0 ? void 0 : complete(_data_); | ||
} else { | ||
// 下面兼容老版本(老版本消息识别不明确,导致 H5 中走 success/fail 逻辑可能岔了) | ||
// @ts-ignore | ||
if (data === null || data === void 0 ? void 0 : data.error) { | ||
fail === null || fail === void 0 ? void 0 : fail(data); | ||
} else { | ||
success === null || success === void 0 ? void 0 : success(data); | ||
} | ||
complete === null || complete === void 0 ? void 0 : complete(data); | ||
} | ||
delete callMap[serialId]; | ||
}; | ||
@@ -150,0 +180,0 @@ // 代码参考:https://alex.alipay.com/antcode/qianyu.fzy/af-appx/blob/r20191223-1.24.0/src/web-view/embed/index.tsx |
@@ -1,4 +0,3 @@ | ||
import { AliJsApi } from '@hylid/types'; | ||
import { AliJsApi, AsyncCallback } from '@hylid/types'; | ||
import { JsApiConfig } from './types'; | ||
import { AsyncCallback } from '@hylid/types'; | ||
export declare const alipayJSBridge: (cb: Function) => any; | ||
@@ -5,0 +4,0 @@ export declare function webCall<T extends keyof AliJsApi.Api>(apiName: T | ({} & string), options?: any, config?: JsApiConfig): void; |
{ | ||
"name": "@hylid/call", | ||
"version": "4.0.0-alpha.18", | ||
"version": "4.0.0-alpha.19", | ||
"main": "lib/index.js", | ||
@@ -9,4 +9,4 @@ "files": [ | ||
"dependencies": { | ||
"@hylid/env": "^4.0.0-alpha.18", | ||
"@hylid/types": "^4.0.0-alpha.18" | ||
"@hylid/env": "^4.0.0-alpha.19", | ||
"@hylid/types": "^4.0.0-alpha.19" | ||
}, | ||
@@ -13,0 +13,0 @@ "publishConfig": { |
40667
1257
Updated@hylid/env@^4.0.0-alpha.19
Updated@hylid/types@^4.0.0-alpha.19