Skip to content

Commit

Permalink
fix(runtime-mini): 添加微信转其他端 jsapi nextTick 的兼容支持
Browse files Browse the repository at this point in the history
  • Loading branch information
BboyZaki committed Sep 7, 2023
1 parent b5787dd commit 3e4cb91
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/runtime-mini/src/wechat/apis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getGlobalObject, transformApis } from '@morjs/runtime-base'
import {
getGlobalObject,
IAPITransformConfig,
transformApis
} from '@morjs/runtime-base'

/**
* 微信需要被 promisified 的接口
Expand Down Expand Up @@ -142,12 +146,26 @@ export const needPromisfiedApis = [
'writeBLECharacteristicValue'
]

const apiTransformConfig: IAPITransformConfig = {
nextTick: {
fn: function (global, callback) {
if (typeof callback !== 'function') return
if (typeof global?.nextTick === 'function') {
return global.nextTick(callback)
} else {
return setTimeout(callback, 0)
}
}
}
}

export function initApi(mor: Record<string, any>) {
transformApis(
mor,
getGlobalObject(),
{
needPromisfiedApis
needPromisfiedApis,
apiTransformConfig
},
false,
false
Expand Down

0 comments on commit 3e4cb91

Please sign in to comment.