Skip to content

Commit

Permalink
fix(mp-weixin): wx wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Jan 14, 2023
1 parent b19a1b9 commit 5a47596
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions packages/uni-mp-weixin/dist/wx.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
const hasOwnProperty = Object.prototype.hasOwnProperty

function hasOwn(obj, key) {
return hasOwnProperty.call(obj, key)
}

function isFn(fn) {
return typeof fn === 'function'
}

const objectKeys = [
'qy',
'env',
Expand All @@ -17,22 +7,24 @@ const objectKeys = [
'cloud',
'serviceMarket',
'router',
'worklet'
'worklet',
]

const oldWx = globalThis[['w', 'x'].join('')]

function isWxKey(key) {
return objectKeys.indexOf(key) > -1 || typeof oldWx[key] === 'function'
}

function initWx() {
const WxProxyHandlers = {
get(target, key) {
if (hasOwn(target, key)) {
return target[key]
}
if (objectKeys.indexOf(key) > -1 || isFn(oldWx[key])) {
return oldWx[key]
const newWx = {}
for (const key in oldWx) {
if (isWxKey(key)) {
// TODO wrapper function
newWx[key] = oldWx[key]
}
}
}
return new Proxy({}, WxProxyHandlers)
return newWx
}
const wxProxy = initWx()
globalThis[['w', 'x'].join('')] = wxProxy
Expand Down

0 comments on commit 5a47596

Please sign in to comment.