Browse Source

Pull request #2843: KERNEL-11580 fix: 内存泄漏问题

Merge in VISUAL/fineui from ~DAILER/fineui:master to master

* commit 'f77d9b396e63ebfd3be6812aa767f9ad770907af':
  KERNEL-11580 fix: 内存泄漏问题
es6
Dailer 2 years ago
parent
commit
4548006800
  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. 10
      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; var self = this, o = this.options;
this._initCombo(); 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) { this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) { if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) { if (type === BI.Events.EXPAND) {
@ -82,7 +84,7 @@
element: this element: this
}, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, {
items: [ items: [
{el: this.combo} { el: this.combo }
] ]
})))); }))));
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
@ -113,7 +115,7 @@
var enterPopup = false; var enterPopup = false;
function hide (e) { function hide(e) {
if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid() && o.toggle === true) { if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid() && o.toggle === true) {
self._hideView(e); self._hideView(e);
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo); self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo);
@ -255,7 +257,7 @@
scrolly: false, scrolly: false,
element: this.options.container || this, element: this.options.container || this,
items: [ items: [
{el: this.popupView} { el: this.popupView }
] ]
}); });
this._rendered = true; this._rendered = true;

8
src/base/combination/combo.js

@ -50,7 +50,9 @@
var self = this, o = this.options; var self = this, o = this.options;
this._initCombo(); 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) { this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) { if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) { if (type === BI.Events.EXPAND) {
@ -88,7 +90,7 @@
element: this element: this
}, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, {
items: [ items: [
{el: this.combo} { el: this.combo }
] ]
})))); }))));
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
@ -153,7 +155,7 @@
this._assertPopupViewRender(); this._assertPopupViewRender();
this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW); this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW);
// popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下
this.popupView.css({left: -999999999, top: -99999999}); this.popupView.css({ left: -999999999, top: -99999999 });
this.popupView.visible(); this.popupView.visible();
BI.each(needHideWhenAnotherComboOpen, function (i, combo) { BI.each(needHideWhenAnotherComboOpen, function (i, combo) {
if (i !== self.getName()) { 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._expanded = !!o.el.open;
this._initExpander(); 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) { this.expander.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) { if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) { if (type === BI.Events.EXPAND) {
@ -63,7 +65,7 @@ BI.Expander = BI.inherit(BI.Widget, {
scrolly: false, scrolly: false,
element: this, element: this,
items: [ items: [
{el: this.expander} { el: this.expander }
] ]
}); });
o.isDefaultInit && this._assertPopupView(); o.isDefaultInit && this._assertPopupView();
@ -167,7 +169,7 @@ BI.Expander = BI.inherit(BI.Widget, {
scrolly: false, scrolly: false,
element: this, element: this,
items: [ items: [
{el: this.popupView} { el: this.popupView }
] ]
}); });
this._rendered = true; 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; var self = this, o = this.options;
this._initSwitcher(); 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) { this.switcher.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) { if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) { if (type === BI.Events.EXPAND) {
@ -63,7 +65,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
scrolly: false, scrolly: false,
element: this, element: this,
items: [ items: [
{el: this.switcher} { el: this.switcher }
] ]
}); });
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
@ -136,7 +138,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
if (!this._created) { if (!this._created) {
this.popupView = BI.createWidget(o.popup, { this.popupView = BI.createWidget(o.popup, {
type: "bi.button_group", 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", cls: "switcher-popup",
layouts: [{ layouts: [{
type: "bi.vertical", type: "bi.vertical",
@ -157,7 +159,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
scrolly: false, scrolly: false,
element: this, element: this,
items: [ items: [
{el: this.popupView} { el: this.popupView }
] ]
}); });
} }

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

@ -49,7 +49,9 @@ BI.BasicButton = BI.inherit(BI.Single, {
this.setSelected(true); this.setSelected(true);
} }
// 延迟绑定事件,这样可以将自己绑定的事情优先执行 // 延迟绑定事件,这样可以将自己绑定的事情优先执行
BI.nextTick(this.bindEvent.bind(this)); BI.nextTick(() => {
!this.isDestroyed() && this.bindEvent();
});
BI.BasicButton.superclass._initRef.apply(this, arguments); BI.BasicButton.superclass._initRef.apply(this, arguments);
}, },
@ -224,7 +226,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
"trailing": false "trailing": false
}); });
function ev (e) { function ev(e) {
if (o.stopEvent) { if (o.stopEvent) {
e.stopEvent(); e.stopEvent();
} }
@ -233,7 +235,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
} }
} }
function clk (e) { function clk(e) {
ev(e); ev(e);
if (!self.isEnabled() || (self.isOnce() && self.isSelected())) { if (!self.isEnabled() || (self.isOnce() && self.isSelected())) {
return; return;
@ -297,7 +299,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
onClick.apply(self, arguments); onClick.apply(self, arguments);
} }
function getBubble () { function getBubble() {
var bubble = self.options.bubble; var bubble = self.options.bubble;
if (BI.isFunction(bubble)) { if (BI.isFunction(bubble)) {
return 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; 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; var hooks = [], hook;
hook = self[life]; hook = self[life];
if (hook) { if (hook) {
@ -124,7 +124,7 @@
var initCallbackCalled = false; var initCallbackCalled = false;
var renderCallbackCalled = false; var renderCallbackCalled = false;
function init () { function init() {
// 加个保险 // 加个保险
if (initCallbackCalled === true) { if (initCallbackCalled === true) {
_global.console && console.error("组件: 请检查beforeInit内部的写法,callback只能执行一次"); _global.console && console.error("组件: 请检查beforeInit内部的写法,callback只能执行一次");
@ -132,7 +132,7 @@
} }
initCallbackCalled = true; initCallbackCalled = true;
function render () { function render() {
// 加个保险 // 加个保险
if (renderCallbackCalled === true) { if (renderCallbackCalled === true) {
_global.console && console.error("组件: 请检查beforeRender内部的写法,callback只能执行一次"); _global.console && console.error("组件: 请检查beforeRender内部的写法,callback只能执行一次");
@ -246,8 +246,8 @@
return getter.call(self, self); return getter.call(self, self);
}, (handler && function (v) { }, (handler && function (v) {
handler.call(self, self, v); handler.call(self, self, v);
}) || BI.emptyFn, BI.extend({deep: true}, options)); }) || BI.emptyFn, BI.extend({ deep: true }, options));
this._watchers.push(function unwatchFn () { this._watchers.push(function unwatchFn() {
watcher.teardown(); watcher.teardown();
}); });
return watcher.value; return watcher.value;
@ -346,6 +346,7 @@
_initState: function () { _initState: function () {
this._isMounted = false; this._isMounted = false;
this._isDestroyed = false;
}, },
__initWatch: function () { __initWatch: function () {
@ -449,6 +450,10 @@
return this._isMounted; return this._isMounted;
}, },
isDestroyed: function () {
return this._isDestroyed;
},
setWidth: function (w) { setWidth: function (w) {
this.options.width = w; this.options.width = w;
this._initElementWidth(); this._initElementWidth();
@ -681,11 +686,11 @@
}, },
isEnabled: function () { isEnabled: function () {
return this.options.disabled === true ? false: !this.options._disabled; return this.options.disabled === true ? false : !this.options._disabled;
}, },
isValid: function () { isValid: function () {
return this.options.invalid === true ? false: !this.options._invalid; return this.options.invalid === true ? false : !this.options._invalid;
}, },
isVisible: function () { isVisible: function () {
@ -732,6 +737,7 @@
this._isMounted = false; this._isMounted = false;
callLifeHook(this, "destroyed"); callLifeHook(this, "destroyed");
this.destroyed = null; this.destroyed = null;
this._isDestroyed = true;
}, },
_unMount: function () { _unMount: function () {
@ -825,12 +831,12 @@
BI.Widget.context = context = contextStack.pop(); BI.Widget.context = context = contextStack.pop();
}; };
function pushTarget (_current) { function pushTarget(_current) {
if (current) currentStack.push(current); if (current) currentStack.push(current);
BI.Widget.current = current = _current; BI.Widget.current = current = _current;
} }
function popTarget () { function popTarget() {
BI.Widget.current = current = currentStack.pop(); BI.Widget.current = current = currentStack.pop();
} }

Loading…
Cancel
Save