Skip to content

Commit

Permalink
fix(shared): 修复小程序createIntersectionObserver方法失效的问题,fix #14563 (#14583)
Browse files Browse the repository at this point in the history
* fix(shared): 修复小程序createIntersectionObserver方法失效的问题,fix #14563

* chore: 调整写法
  • Loading branch information
Chen-jj committed Sep 22, 2023
1 parent fb07ac5 commit fd9a7d9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/shared/src/native-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ function equipCommonApis (taro, global, apis: Record<string, any> = {}) {
}
}
taro.createSelectorQuery = delayRef(taro, global, 'createSelectorQuery', 'exec')
taro.createIntersectionObserver = delayRef(taro, global, 'createIntersectionObserver', 'observe')
}

/**
Expand All @@ -406,11 +407,11 @@ function equipTaskMethodsIntoPromise (task, promise) {
}

function delayRef (taro, global, name: string, method: string) {
return function () {
const res = global[name]()
return function (...args) {
const res = global[name](...args)
const raw = res[method].bind(res)
res[method] = function (...args) {
taro.nextTick(() => raw(...args))
res[method] = function (...methodArgs) {
taro.nextTick(() => raw(...methodArgs))
}
return res
}
Expand Down

0 comments on commit fd9a7d9

Please sign in to comment.