Skip to content

Commit

Permalink
feat(taro): 要求传入小程序原生对象的 api ,可以通过传入 taro 实例来解决
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 7, 2019
1 parent 37461e5 commit 7300861
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -13,7 +13,8 @@ module.exports = {
tt: true,
getApp: true,
__wxRoute: true,
getCurrentPages: true
getCurrentPages: true,
requirePlugin: true
},
rules: {
'no-unused-expressions': 0,
Expand Down
1 change: 1 addition & 0 deletions packages/taro-alipay/src/component.js
Expand Up @@ -33,6 +33,7 @@ class BaseComponent {
this.state = {}
this.props = {}
this.$componentType = isPage ? 'PAGE' : 'COMPONENT'
this.isTaroComponent = this.$componentType && this.$router && this._pendingStates
}
_constructor (props) {
this.props = props || {}
Expand Down
8 changes: 7 additions & 1 deletion packages/taro-alipay/src/native-api.js
Expand Up @@ -342,7 +342,13 @@ function processApis (taro) {
query.in = function () { return query }
return query
}
return my[key].apply(my, args)
const argsLen = args.length
const newArgs = args.concat()
const lastArg = newArgs[argsLen - 1]
if (lastArg && lastArg.isTaroComponent && lastArg.$scope) {
newArgs.splice(argsLen - 1, 1, lastArg.$scope)
}
return my[key].apply(my, newArgs)
}
}
})
Expand Down
1 change: 1 addition & 0 deletions packages/taro-swan/src/component.js
Expand Up @@ -35,6 +35,7 @@ class BaseComponent {
this.state = {}
this.props = {}
this.$componentType = isPage ? 'PAGE' : 'COMPONENT'
this.isTaroComponent = this.$componentType && this.$router && this._pendingStates
}
_constructor (props) {
this.props = props || {}
Expand Down
8 changes: 7 additions & 1 deletion packages/taro-swan/src/native-api.js
Expand Up @@ -133,7 +133,13 @@ function processApis (taro) {
}
} else {
taro[key] = (...args) => {
return swan[key].apply(swan, args)
const argsLen = args.length
const newArgs = args.concat()
const lastArg = newArgs[argsLen - 1]
if (lastArg && lastArg.isTaroComponent && lastArg.$scope) {
newArgs.splice(argsLen - 1, 1, lastArg.$scope)
}
return swan[key].apply(swan, newArgs)
}
}
})
Expand Down
1 change: 1 addition & 0 deletions packages/taro-tt/src/component.js
Expand Up @@ -35,6 +35,7 @@ class BaseComponent {
this.state = {}
this.props = {}
this.$componentType = isPage ? 'PAGE' : 'COMPONENT'
this.isTaroComponent = this.$componentType && this.$router && this._pendingStates
}
_constructor (props) {
this.props = props || {}
Expand Down
8 changes: 7 additions & 1 deletion packages/taro-tt/src/native-api.js
Expand Up @@ -133,7 +133,13 @@ function processApis (taro) {
}
} else {
taro[key] = (...args) => {
return tt[key].apply(tt, args)
const argsLen = args.length
const newArgs = args.concat()
const lastArg = newArgs[argsLen - 1]
if (lastArg && lastArg.isTaroComponent && lastArg.$scope) {
newArgs.splice(argsLen - 1, 1, lastArg.$scope)
}
return tt[key].apply(tt, newArgs)
}
}
})
Expand Down
1 change: 1 addition & 0 deletions packages/taro-weapp/src/component.js
Expand Up @@ -37,6 +37,7 @@ class BaseComponent {
this.state = {}
this.props = props
this.$componentType = isPage ? 'PAGE' : 'COMPONENT'
this.isTaroComponent = this.$componentType && this.$router && this._pendingStates
}
_constructor (props) {
this.props = props || {}
Expand Down
8 changes: 7 additions & 1 deletion packages/taro-weapp/src/native-api.js
Expand Up @@ -164,7 +164,13 @@ function processApis (taro) {
}
} else {
taro[key] = (...args) => {
return wx[key].apply(wx, args)
const argsLen = args.length
const newArgs = args.concat()
const lastArg = newArgs[argsLen - 1]
if (lastArg && lastArg.isTaroComponent && lastArg.$scope) {
newArgs.splice(argsLen - 1, 1, lastArg.$scope)
}
return wx[key].apply(wx, newArgs)
}
}
})
Expand Down

0 comments on commit 7300861

Please sign in to comment.