Browse Source

Pull request #3176: KERNEL-13158: 包裹BI.Widget.pushContext()

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

* commit '3e440e09fb18aec0f703a3dfa51a0c5b4323fe63':
  KERNEL-13158: 包裹BI.Widget.pushContext()
  KERNEL-13158: 包裹BI.Widget.pushContext()
es6
guy-王川 2 years ago
parent
commit
72589c7a62
  1. 12
      src/base/combination/group.button.js
  2. 19
      src/base/combination/navigation.js
  3. 17
      src/base/combination/tab.js
  4. 21
      src/core/4.widget.js

12
src/base/combination/group.button.js

@ -42,11 +42,13 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
},
_createBtns: function (items) {
BI.Widget.pushContext(this);
var btns = BI.createWidgets(BI.createItems(items, {
type: "bi.text_button",
}));
BI.Widget.popContext();
var btns;
BI.Widget.execWithContext(this, function () {
btns = BI.createWidgets(BI.createItems(items, {
type: "bi.text_button",
}));
});
return btns;
},

19
src/base/combination/navigation.js

@ -43,11 +43,10 @@ BI.Navigation = BI.inherit(BI.Widget, {
return self.showIndex + v;
},
cardCreator: function (v) {
BI.Widget.pushContext(self);
var card = o.cardCreator(v);
BI.Widget.popContext();
self.cardMap[v] = card;
return card;
BI.Widget.execWithContext(self, function () {
self.cardMap[v] = o.cardCreator(v);
});
return self.cardMap[v];
},
afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, this),
@ -104,12 +103,12 @@ BI.Navigation = BI.inherit(BI.Widget, {
},
_assertCard: function (v) {
var self = this, o = this.options;
if (!this.layout.isCardExisted(v)) {
BI.Widget.pushContext(this);
var card = this.options.cardCreator(v);
BI.Widget.popContext();
this.cardMap[v] = card;
this.layout.addCardByName(v, card);
BI.Widget.execWithContext(self, function () {
self.cardMap[v] = o.cardCreator(v);
});
this.layout.addCardByName(v, this.cardMap[v]);
this.afterCardCreated(v);
}
},

17
src/base/combination/tab.js

@ -43,10 +43,11 @@ BI.Tab = BI.inherit(BI.Widget, {
eventObj: this.tab,
cardLayout: this.layout,
cardCreator: function (v) {
var card = o.cardCreator.apply(self, arguments);
self.cardMap[v] = card;
BI.Widget.execWithContext(self, function () {
self.cardMap[v] = o.cardCreator.apply(self, arguments);
});
return card;
return self.cardMap[v];
},
afterCardShow: function (v) {
self._deleteOtherCards(v);
@ -71,12 +72,12 @@ BI.Tab = BI.inherit(BI.Widget, {
},
_assertCard: function (v) {
var self = this, o = this.options;
if (!this.layout.isCardExisted(v)) {
BI.Widget.pushContext(this);
var card = this.options.cardCreator(v);
BI.Widget.popContext();
this.cardMap[v] = card;
this.layout.addCardByName(v, card);
BI.Widget.execWithContext(this, function () {
self.cardMap[v] = o.cardCreator.apply(self, arguments);
});
this.layout.addCardByName(v, this.cardMap[v]);
}
},

21
src/core/4.widget.js

@ -857,6 +857,17 @@
BI.Widget.context = context = contextStack.pop();
};
BI.Widget.execWithContext = function (context, execFunc) {
BI.Widget.pushContext(context);
try {
execFunc();
} catch (e) {
throw e;
} finally {
BI.Widget.popContext();
}
};
function pushTarget(_current) {
if (current) currentStack.push(current);
BI.Widget.current = current = _current;
@ -927,16 +938,6 @@
return vm;
};
BI.execWithContext = function (_context, fn) {
BI.Widget.pushContext(_context);
try {
fn();
} catch (e) {
// nothing
}
BI.Widget.popContext();
};
BI.watch = function (vm, watch, handler) {
// 必须要保证组件当前环境存在
if (BI.Widget.current) {

Loading…
Cancel
Save