Browse Source

KERNEL-13158: 包裹BI.Widget.pushContext()

es6
guy 2 years ago
parent
commit
cae1503174
  1. 12
      src/base/combination/group.button.js
  2. 19
      src/base/combination/navigation.js
  3. 17
      src/base/combination/tab.js
  4. 11
      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]);
}
},

11
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;

Loading…
Cancel
Save