@tarojs/runtime 3.4.0-beta.3 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime.esm.js +15 -11
- package/dist/runtime.esm.js.map +1 -1
- package/package.json +4 -4
package/dist/runtime.esm.js
CHANGED
|
@@ -1359,14 +1359,7 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1359
1359
|
}
|
|
1360
1360
|
addEventListener(type, handler, options) {
|
|
1361
1361
|
var _a, _b;
|
|
1362
|
-
|
|
1363
|
-
// 这会导致多层停止冒泡失败:view -> view(handler.stop = false) -> view(handler.stop = true)
|
|
1364
|
-
// 这样解决:view -> view(handlerA.stop = false) -> view(handlerB.stop = false)
|
|
1365
|
-
// 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
|
|
1366
|
-
const oldHandler = handler;
|
|
1367
|
-
handler = function () {
|
|
1368
|
-
oldHandler.apply(this, arguments); // this 指向 Element
|
|
1369
|
-
};
|
|
1362
|
+
type = type.toLowerCase();
|
|
1370
1363
|
(_b = (_a = this.hooks).onAddEvent) === null || _b === void 0 ? void 0 : _b.call(_a, type, handler, options, this);
|
|
1371
1364
|
if (type === 'regionchange') {
|
|
1372
1365
|
// map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
|
|
@@ -1374,8 +1367,6 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1374
1367
|
this.addEventListener('end', handler, options);
|
|
1375
1368
|
return;
|
|
1376
1369
|
}
|
|
1377
|
-
type = type.toLowerCase();
|
|
1378
|
-
const handlers = this.__handlers[type];
|
|
1379
1370
|
let isCapture = Boolean(options);
|
|
1380
1371
|
let isOnce = false;
|
|
1381
1372
|
if (isObject(options)) {
|
|
@@ -1391,6 +1382,16 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1391
1382
|
return;
|
|
1392
1383
|
}
|
|
1393
1384
|
process.env.NODE_ENV !== 'production' && warn(isCapture, 'Taro 暂未实现 event 的 capture 特性。');
|
|
1385
|
+
// 某些框架,如 PReact 有委托的机制,handler 始终是同一个函数
|
|
1386
|
+
// 这会导致多层停止冒泡失败:view -> view(handler.stop = false) -> view(handler.stop = true)
|
|
1387
|
+
// 这样解决:view -> view(handlerA.stop = false) -> view(handlerB.stop = false)
|
|
1388
|
+
// 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
|
|
1389
|
+
const oldHandler = handler;
|
|
1390
|
+
handler = function () {
|
|
1391
|
+
oldHandler.apply(this, arguments); // this 指向 Element
|
|
1392
|
+
};
|
|
1393
|
+
handler.oldHandler = oldHandler;
|
|
1394
|
+
const handlers = this.__handlers[type];
|
|
1394
1395
|
if (isArray(handlers)) {
|
|
1395
1396
|
handlers.push(handler);
|
|
1396
1397
|
}
|
|
@@ -1407,7 +1408,10 @@ let TaroEventTarget = class TaroEventTarget {
|
|
|
1407
1408
|
if (!isArray(handlers)) {
|
|
1408
1409
|
return;
|
|
1409
1410
|
}
|
|
1410
|
-
const index = handlers.
|
|
1411
|
+
const index = handlers.findIndex(item => {
|
|
1412
|
+
if (item === handler || item.oldHandler === handler)
|
|
1413
|
+
return true;
|
|
1414
|
+
});
|
|
1411
1415
|
process.env.NODE_ENV !== 'production' && warn(index === -1, `事件: '${type}' 没有注册在 DOM 中,因此不会被移除。`);
|
|
1412
1416
|
handlers.splice(index, 1);
|
|
1413
1417
|
}
|