Browse Source

KERNEL-11580 fix: 内存泄漏问题

es6
zsmj 2 years ago
parent
commit
e233565442
  1. 10
      src/base/combination/bubble.js
  2. 8
      src/base/combination/combo.js
  3. 8
      src/base/combination/expander.js
  4. 10
      src/base/combination/switcher.js
  5. 12
      src/base/single/button/button.basic.js
  6. 24
      src/core/4.widget.js

10
src/base/combination/bubble.js

@ -44,7 +44,9 @@
var self = this, o = this.options;
this._initCombo();
// 延迟绑定事件,这样可以将自己绑定的事情优先执行
BI.nextTick(this._initPullDownAction.bind(this));
BI.nextTick(() => {
!this.isDestroyed() && this._initPullDownAction();
});
this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) {
@ -82,7 +84,7 @@
element: this
}, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, {
items: [
{el: this.combo}
{ el: this.combo }
]
}))));
o.isDefaultInit && (this._assertPopupView());
@ -113,7 +115,7 @@
var enterPopup = false;
function hide (e) {
function hide(e) {
if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid() && o.toggle === true) {
self._hideView(e);
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo);
@ -255,7 +257,7 @@
scrolly: false,
element: this.options.container || this,
items: [
{el: this.popupView}
{ el: this.popupView }
]
});
this._rendered = true;

8
src/base/combination/combo.js

@ -50,7 +50,9 @@
var self = this, o = this.options;
this._initCombo();
// 延迟绑定事件,这样可以将自己绑定的事情优先执行
BI.nextTick(this._initPullDownAction.bind(this));
BI.nextTick(() => {
!this.isDestroyed() && this._initPullDownAction();
});
this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) {
@ -88,7 +90,7 @@
element: this
}, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, {
items: [
{el: this.combo}
{ el: this.combo }
]
}))));
o.isDefaultInit && (this._assertPopupView());
@ -153,7 +155,7 @@
this._assertPopupViewRender();
this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW);
// popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下
this.popupView.css({left: -999999999, top: -99999999});
this.popupView.css({ left: -999999999, top: -99999999 });
this.popupView.visible();
BI.each(needHideWhenAnotherComboOpen, function (i, combo) {
if (i !== self.getName()) {

8
src/base/combination/expander.js

@ -26,7 +26,9 @@ BI.Expander = BI.inherit(BI.Widget, {
this._expanded = !!o.el.open;
this._initExpander();
// 延迟绑定事件,这样可以将自己绑定的事情优先执行
BI.nextTick(this._initPullDownAction.bind(this));
BI.nextTick(() => {
!this.isDestroyed() && this._initPullDownAction();
});
this.expander.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) {
@ -63,7 +65,7 @@ BI.Expander = BI.inherit(BI.Widget, {
scrolly: false,
element: this,
items: [
{el: this.expander}
{ el: this.expander }
]
});
o.isDefaultInit && this._assertPopupView();
@ -167,7 +169,7 @@ BI.Expander = BI.inherit(BI.Widget, {
scrolly: false,
element: this,
items: [
{el: this.popupView}
{ el: this.popupView }
]
});
this._rendered = true;

10
src/base/combination/switcher.js

@ -26,7 +26,9 @@ BI.Switcher = BI.inherit(BI.Widget, {
var self = this, o = this.options;
this._initSwitcher();
// 延迟绑定事件,这样可以将自己绑定的事情优先执行
BI.nextTick(this._initPullDownAction.bind(this));
BI.nextTick(() => {
!this.isDestroyed() && this._initPullDownAction();
});
this.switcher.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) {
@ -63,7 +65,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
scrolly: false,
element: this,
items: [
{el: this.switcher}
{ el: this.switcher }
]
});
o.isDefaultInit && (this._assertPopupView());
@ -136,7 +138,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
if (!this._created) {
this.popupView = BI.createWidget(o.popup, {
type: "bi.button_group",
element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({container: this}, o.masker)),
element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({ container: this }, o.masker)),
cls: "switcher-popup",
layouts: [{
type: "bi.vertical",
@ -157,7 +159,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
scrolly: false,
element: this,
items: [
{el: this.popupView}
{ el: this.popupView }
]
});
}

12
src/base/single/button/button.basic.js

@ -49,7 +49,9 @@ BI.BasicButton = BI.inherit(BI.Single, {
this.setSelected(true);
}
// 延迟绑定事件,这样可以将自己绑定的事情优先执行
BI.nextTick(this.bindEvent.bind(this));
BI.nextTick(() => {
!this.isDestroyed() && this.bindEvent();
});
BI.BasicButton.superclass._initRef.apply(this, arguments);
},
@ -211,7 +213,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
// enter键等同于点击
o.attributes && o.attributes.zIndex >= 0 && hand.keyup(function (e) {
if (e.keyCode === BI.KeyCode.ENTER) {
clk(e);
clk(e);
}
});
break;
@ -224,7 +226,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
"trailing": false
});
function ev (e) {
function ev(e) {
if (o.stopEvent) {
e.stopEvent();
}
@ -233,7 +235,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
}
}
function clk (e) {
function clk(e) {
ev(e);
if (!self.isEnabled() || (self.isOnce() && self.isSelected())) {
return;
@ -297,7 +299,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
onClick.apply(self, arguments);
}
function getBubble () {
function getBubble() {
var bubble = self.options.bubble;
if (BI.isFunction(bubble)) {
return bubble();

24
src/core/4.widget.js

@ -17,7 +17,7 @@
var requestAnimationFrame = _global.requestAnimationFrame || _global.webkitRequestAnimationFrame || _global.mozRequestAnimationFrame || _global.oRequestAnimationFrame || _global.msRequestAnimationFrame || _global.setTimeout;
function callLifeHook (self, life) {
function callLifeHook(self, life) {
var hooks = [], hook;
hook = self[life];
if (hook) {
@ -124,7 +124,7 @@
var initCallbackCalled = false;
var renderCallbackCalled = false;
function init () {
function init() {
// 加个保险
if (initCallbackCalled === true) {
_global.console && console.error("组件: 请检查beforeInit内部的写法,callback只能执行一次");
@ -132,7 +132,7 @@
}
initCallbackCalled = true;
function render () {
function render() {
// 加个保险
if (renderCallbackCalled === true) {
_global.console && console.error("组件: 请检查beforeRender内部的写法,callback只能执行一次");
@ -246,8 +246,8 @@
return getter.call(self, self);
}, (handler && function (v) {
handler.call(self, self, v);
}) || BI.emptyFn, BI.extend({deep: true}, options));
this._watchers.push(function unwatchFn () {
}) || BI.emptyFn, BI.extend({ deep: true }, options));
this._watchers.push(function unwatchFn() {
watcher.teardown();
});
return watcher.value;
@ -346,6 +346,7 @@
_initState: function () {
this._isMounted = false;
this._isDestroyed = false;
},
__initWatch: function () {
@ -449,6 +450,10 @@
return this._isMounted;
},
isDestroyed: function () {
return this._isDestroyed;
},
setWidth: function (w) {
this.options.width = w;
this._initElementWidth();
@ -681,11 +686,11 @@
},
isEnabled: function () {
return this.options.disabled === true ? false: !this.options._disabled;
return this.options.disabled === true ? false : !this.options._disabled;
},
isValid: function () {
return this.options.invalid === true ? false: !this.options._invalid;
return this.options.invalid === true ? false : !this.options._invalid;
},
isVisible: function () {
@ -732,6 +737,7 @@
this._isMounted = false;
callLifeHook(this, "destroyed");
this.destroyed = null;
this._isDestroyed = true;
},
_unMount: function () {
@ -825,12 +831,12 @@
BI.Widget.context = context = contextStack.pop();
};
function pushTarget (_current) {
function pushTarget(_current) {
if (current) currentStack.push(current);
BI.Widget.current = current = _current;
}
function popTarget () {
function popTarget() {
BI.Widget.current = current = currentStack.pop();
}

Loading…
Cancel
Save