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) { _createBtns: function (items) {
BI.Widget.pushContext(this); var btns;
var btns = BI.createWidgets(BI.createItems(items, { BI.Widget.execWithContext(this, function () {
type: "bi.text_button", btns = BI.createWidgets(BI.createItems(items, {
})); type: "bi.text_button",
BI.Widget.popContext(); }));
});
return btns; return btns;
}, },

19
src/base/combination/navigation.js

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

17
src/base/combination/tab.js

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

21
src/core/4.widget.js

@ -857,6 +857,17 @@
BI.Widget.context = context = contextStack.pop(); 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) { function pushTarget(_current) {
if (current) currentStack.push(current); if (current) currentStack.push(current);
BI.Widget.current = current = _current; BI.Widget.current = current = _current;
@ -927,16 +938,6 @@
return vm; 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) { BI.watch = function (vm, watch, handler) {
// 必须要保证组件当前环境存在 // 必须要保证组件当前环境存在
if (BI.Widget.current) { if (BI.Widget.current) {

Loading…
Cancel
Save