From 13ea18b9e740f17443950e5106a1ea9d610343e6 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 16 Mar 2020 11:28:50 +0800 Subject: [PATCH] =?UTF-8?q?BI-61560=20refactor:=20=E6=8F=90=E4=BE=9Bmixin?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E5=86=8Ckey=E5=9F=8B=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/inject.js | 62 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/core/inject.js b/src/core/inject.js index 30a15a2f8d..78a89d8499 100644 --- a/src/core/inject.js +++ b/src/core/inject.js @@ -143,45 +143,49 @@ } }; - var callPoint = function (inst, type) { - if (points[type]) { - for (var action in points[type]) { - var bfns = points[type][action].before; - if (bfns) { - BI.aspect.before(inst, action, function (bfns) { - return function () { - for (var i = 0, len = bfns.length; i < len; i++) { - try { - bfns[i].apply(inst, arguments); - } catch (e) { - _global.console && console.error(e); + var callPoint = function (inst, types) { + types = BI.isArray(types) ? types : [types]; + BI.each(types, function (idx, type) { + if (points[type]) { + for (var action in points[type]) { + var bfns = points[type][action].before; + if (bfns) { + BI.aspect.before(inst, action, function (bfns) { + return function () { + for (var i = 0, len = bfns.length; i < len; i++) { + try { + bfns[i].apply(inst, arguments); + } catch (e) { + _global.console && console.error(e); + } } - } - }; - }(bfns)); - } - var afns = points[type][action].after; - if (afns) { - BI.aspect.after(inst, action, function (afns) { - return function () { - for (var i = 0, len = afns.length; i < len; i++) { - try { - afns[i].apply(inst, arguments); - } catch (e) { - _global.console && console.error(e); + }; + }(bfns)); + } + var afns = points[type][action].after; + if (afns) { + BI.aspect.after(inst, action, function (afns) { + return function () { + for (var i = 0, len = afns.length; i < len; i++) { + try { + afns[i].apply(inst, arguments); + } catch (e) { + _global.console && console.error(e); + } } - } - }; - }(afns)); + }; + }(afns)); + } } } - } + }); }; BI.Models = { getModel: function (type, config) { var inst = new modelInjection[type](config); inst._constructor && inst._constructor(config); + inst.mixins && callPoint(inst, inst.mixins); callPoint(inst, type); return inst; }