From 07dbabbfbff0ad7ffe9aa81ef744d4976893e84e Mon Sep 17 00:00:00 2001 From: zsmj Date: Mon, 17 Oct 2022 15:17:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=20chore:=20=20listeners=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=AF=B9=E8=B1=A1,=E5=AF=B9=E8=B1=A1=E7=9A=84value?= =?UTF-8?q?=E6=94=AF=E6=8C=81array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/3.ob.js | 19 ++++++++++--------- src/core/5.inject.js | 8 +++++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/core/3.ob.js b/src/core/3.ob.js index a9019c3a8..f23ebd67b 100644 --- a/src/core/3.ob.js +++ b/src/core/3.ob.js @@ -32,9 +32,7 @@ this._constructor(config); }; BI._.extend(OB.prototype, { - props: {}, - init: null, - destroyed: null, + props: {}, init: null, destroyed: null, _constructor: function (config) { this._initProps(config); @@ -71,6 +69,12 @@ self.on(eventName, lis); return; } + if (BI._.isArray(lis)) { + BI._.each(lis, function (l) { + self.on(eventName, l); + }); + return; + } (lis.target ? lis.target : self)[lis.once ? "once" : "on"](lis.eventName, BI._.bind(lis.action, self)); }); delete this.options.listeners; @@ -139,8 +143,7 @@ this.un(eventName, proxy); }; this.on(eventName, proxy); - }, - /** + }, /** * 解除观察者绑定的指定事件 * @param {String} eventName 要解除绑定事件的名字 * @param {Function} fn 事件对应的执行函数,该参数是可选的,没有该参数时,将解除绑定所有同名字的事件 @@ -163,15 +166,13 @@ this._getEvents()[eventName] = newFns; } } - }, - /** + }, /** * 清除观察者的所有事件绑定 */ purgeListeners: function () { /* alex:清空events*/ this.events = {}; - }, - /** + }, /** * 触发绑定过的事件 * * @param {String} eventName 要触发的事件的名字 diff --git a/src/core/5.inject.js b/src/core/5.inject.js index 5e2cb0a72..f4c28401d 100644 --- a/src/core/5.inject.js +++ b/src/core/5.inject.js @@ -479,9 +479,11 @@ } }]); } else { - w.listeners[BI.Events.MOUNT] = function () { - BI.Plugin.getObject(elType, this); - } + w.listeners[BI.Events.MOUNT] = (w.listeners[BI.Events.MOUNT] || []), concat([ + function () { + BI.Plugin.getObject(elType, this); + } + ]); } } return createWidget(w, context, lazy);