From 73008611cd95e8e77e4bb678c292ba509992784c Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 7 Jan 2019 11:01:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(taro):=20=E8=A6=81=E6=B1=82=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=8E=9F=E7=94=9F=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=9A=84=20api=20=EF=BC=8C=E5=8F=AF=E4=BB=A5=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E4=BC=A0=E5=85=A5=20taro=20=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E6=9D=A5=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 3 ++- packages/taro-alipay/src/component.js | 1 + packages/taro-alipay/src/native-api.js | 8 +++++++- packages/taro-swan/src/component.js | 1 + packages/taro-swan/src/native-api.js | 8 +++++++- packages/taro-tt/src/component.js | 1 + packages/taro-tt/src/native-api.js | 8 +++++++- packages/taro-weapp/src/component.js | 1 + packages/taro-weapp/src/native-api.js | 8 +++++++- 9 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 19c7fbcbc9f8..786484995c1b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,7 +13,8 @@ module.exports = { tt: true, getApp: true, __wxRoute: true, - getCurrentPages: true + getCurrentPages: true, + requirePlugin: true }, rules: { 'no-unused-expressions': 0, diff --git a/packages/taro-alipay/src/component.js b/packages/taro-alipay/src/component.js index 2fdc9a340d47..a73d03481c1d 100644 --- a/packages/taro-alipay/src/component.js +++ b/packages/taro-alipay/src/component.js @@ -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 || {} diff --git a/packages/taro-alipay/src/native-api.js b/packages/taro-alipay/src/native-api.js index 85b4444e3d5f..e27214909c0c 100644 --- a/packages/taro-alipay/src/native-api.js +++ b/packages/taro-alipay/src/native-api.js @@ -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) } } }) diff --git a/packages/taro-swan/src/component.js b/packages/taro-swan/src/component.js index 429f2f6dba8e..523409186df5 100644 --- a/packages/taro-swan/src/component.js +++ b/packages/taro-swan/src/component.js @@ -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 || {} diff --git a/packages/taro-swan/src/native-api.js b/packages/taro-swan/src/native-api.js index 9f382863f34e..e587dac915ce 100644 --- a/packages/taro-swan/src/native-api.js +++ b/packages/taro-swan/src/native-api.js @@ -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) } } }) diff --git a/packages/taro-tt/src/component.js b/packages/taro-tt/src/component.js index ef0e37f0fafa..a49cf756db33 100644 --- a/packages/taro-tt/src/component.js +++ b/packages/taro-tt/src/component.js @@ -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 || {} diff --git a/packages/taro-tt/src/native-api.js b/packages/taro-tt/src/native-api.js index 0106146a526c..82b6eed05680 100644 --- a/packages/taro-tt/src/native-api.js +++ b/packages/taro-tt/src/native-api.js @@ -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) } } }) diff --git a/packages/taro-weapp/src/component.js b/packages/taro-weapp/src/component.js index c72c588eae13..da767bb920e8 100644 --- a/packages/taro-weapp/src/component.js +++ b/packages/taro-weapp/src/component.js @@ -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 || {} diff --git a/packages/taro-weapp/src/native-api.js b/packages/taro-weapp/src/native-api.js index d44ff098ed1f..3dff2bacc5f0 100644 --- a/packages/taro-weapp/src/native-api.js +++ b/packages/taro-weapp/src/native-api.js @@ -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) } } })