Browse Source

Pull request #2331: 无JIAR任务 支持BI.useContext

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

* commit '35dbe38b52096651c85c474d7fa0e5b68e05b020':
  childContext替换成provide
  支持BI.useContext
  支持BI.useContext
es6
guy 3 years ago
parent
commit
86f1b2bbe1
  1. 1
      changelog.md
  2. 61
      dist/fix/fix.js
  3. 56
      src/core/4.widget.js

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志
2.0(2021-12)
- childContext废弃,替换成provide
- 支持BI.useContext获取上下文环境
- BI.Msg.alert支持message传json格式
- 支持BI.config(function(){})进行系统配置

61
dist/fix/fix.js vendored

@ -134,8 +134,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
setImmediate(nextTickHandler);
};
} else if (typeof MessageChannel !== 'undefined' && (isNative(MessageChannel) ||
// PhantomJS
MessageChannel.toString() === '[object MessageChannelConstructor]')) {
// PhantomJS
MessageChannel.toString() === '[object MessageChannelConstructor]')) {
var channel = new MessageChannel();
var port = channel.port2;
channel.port1.onmessage = nextTickHandler;
@ -144,18 +144,18 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
};
} else
/* istanbul ignore next */
if (typeof Promise !== 'undefined' && isNative(Promise)) {
// use microtask in non-DOM environments, e.g. Weex
var p = Promise.resolve();
timerFunc = function timerFunc() {
p.then(nextTickHandler);
};
} else {
// fallback to setTimeout
timerFunc = function timerFunc() {
setTimeout(nextTickHandler, 0);
};
}
if (typeof Promise !== 'undefined' && isNative(Promise)) {
// use microtask in non-DOM environments, e.g. Weex
var p = Promise.resolve();
timerFunc = function timerFunc() {
p.then(nextTickHandler);
};
} else {
// fallback to setTimeout
timerFunc = function timerFunc() {
setTimeout(nextTickHandler, 0);
};
}
return function queueNextTick(cb, ctx) {
var _resolve = void 0;
@ -294,7 +294,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
if (isIE9Below) {
var VBClassPool = {};
window.execScript([// jshint ignore:line
'Function parseVB(code)', '\tExecuteGlobal(code)', 'End Function' //转换一段文本为VB代码
'Function parseVB(code)', '\tExecuteGlobal(code)', 'End Function' //转换一段文本为VB代码
].join('\n'), 'VBScript');
var VBMediator = function VBMediator(instance, accessors, name, value) {
@ -310,7 +310,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
// jshint ignore:line
var buffer = [];
buffer.push('\tPrivate [$vbsetter]', '\tPublic [$accessors]', '\tPublic Default Function [$vbthis](ac' + timeBucket + ', s' + timeBucket + ')', '\t\tSet [$accessors] = ac' + timeBucket + ': set [$vbsetter] = s' + timeBucket, '\t\tSet [$vbthis] = Me', //链式调用
'\tEnd Function');
'\tEnd Function');
//添加普通属性,因为VBScript对象不能像JS那样随意增删属性,必须在这里预先定义好
var uniq = {
$vbthis: true,
@ -323,19 +323,19 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
uniq[name] = true;
}
}
//添加访问器属性
//添加访问器属性
for (name in accessors) {
if (uniq[name]) {
continue;
}
uniq[name] = true;
buffer.push(
//由于不知对方会传入什么,因此set, let都用上
'\tPublic Property Let [' + name + '](val' + timeBucket + ')', //setter
'\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Set [' + name + '](val' + timeBucket + ')', //setter
'\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Get [' + name + ']', //getter
'\tOn Error Resume Next', //必须优先使用set语句,否则它会误将数组当字符串返回
'\t\tSet[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tIf Err.Number <> 0 Then', '\t\t[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tEnd If', '\tOn Error Goto 0', '\tEnd Property');
//由于不知对方会传入什么,因此set, let都用上
'\tPublic Property Let [' + name + '](val' + timeBucket + ')', //setter
'\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Set [' + name + '](val' + timeBucket + ')', //setter
'\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Get [' + name + ']', //getter
'\tOn Error Resume Next', //必须优先使用set语句,否则它会误将数组当字符串返回
'\t\tSet[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tIf Err.Number <> 0 Then', '\t\t[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tEnd If', '\tOn Error Goto 0', '\tEnd Property');
}
for (name in properties) {
@ -353,7 +353,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
className = makeHashCode('VBClass');
window.parseVB('Class ' + className + body);
window.parseVB(['Function ' + className + 'Factory(acc, vbm)', //创建实例并传入两个关键的参数
'\tDim o', '\tSet o = (New ' + className + ')(acc, vbm)', '\tSet ' + className + 'Factory = o', 'End Function'].join('\r\n'));
'\tDim o', '\tSet o = (New ' + className + ')(acc, vbm)', '\tSet ' + className + 'Factory = o', 'End Function'].join('\r\n'));
VBClassPool[body] = className;
}
var ret = window[className + 'Factory'](accessors, VBMediator); //得到其产品
@ -537,10 +537,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
if (this.active) {
var value = this.get();
if (value !== this.value ||
// Deep watchers and watchers on Object/Arrays should fire even
// when the value is the same, because the value may
// have mutated.
_.isObject(value) && options && options.refresh || this.deep) {
// Deep watchers and watchers on Object/Arrays should fire even
// when the value is the same, because the value may
// have mutated.
_.isObject(value) && options && options.refresh || this.deep) {
// set new value
var oldValue = this.value;
this.value = value;
@ -1420,12 +1420,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var context = this.context;
var inject = this.inject;
var childContext = this.childContext;
var provide = this.provide;
var watch$$1 = this.watch;
var actions = this.actions;
var keys = _.keys(this.$$model).concat(_.keys(state)).concat(_.keys(computed)).concat(inject || []).concat(context || []);
var mixins = this.mixins;
defineProps(this, keys);
// deprecated
childContext && defineContext(this, childContext);
provide && defineContext(this, provide);
this.$$model && (this.model.__ob__ = this.$$model.__ob__);
initMixins(this, mixins);
this.init();
@ -1523,4 +1526,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
exports.toJSON = toJSON;
exports.__esModule = true;
});
});

56
src/core/4.widget.js

@ -768,38 +768,50 @@
}
};
BI.useContext = function () {
BI.useContext = function (inject) {
if (BI.Model.target) {
var p = BI.Model.target;
if (inject) {
while (p) {
if (p.$$context && inject in p.$$context) {
return p;
}
p = p._parent;
}
}
}
return BI.Model.target;
};
BI.watch = function (vm, watch, handler) {
if (vm instanceof BI.Model) {
var watchers = [];
if (BI.isKey(watch)) {
var k = watch;
watch = {};
watch[k] = handler;
}
for (var key in watch) {
var innerHandler = watch[key];
if (BI.isArray(handler)) {
for (var i = 0; i < handler.length; i++) {
// 必须要保证组件当前环境存在
if (BI.Widget.current) {
if (vm instanceof BI.Model) {
var watchers = [];
if (BI.isKey(watch)) {
var k = watch;
watch = {};
watch[k] = handler;
}
for (var key in watch) {
var innerHandler = watch[key];
if (BI.isArray(handler)) {
for (var i = 0; i < handler.length; i++) {
watchers.push(Fix.watch(vm.model, key, innerHandler, {
store: vm
}));
}
} else {
watchers.push(Fix.watch(vm.model, key, innerHandler, {
store: vm
}));
}
} else {
watchers.push(Fix.watch(vm.model, key, innerHandler, {
store: vm
}));
}
// vm中一定有_widget
BI.Widget.current._watchers || (BI.Widget.current._watchers = []);
BI.Widget.current._watchers = BI.Widget.current._watchers.concat(watchers);
return;
}
// vm中一定有_widget
vm._widget._watchers || (vm._widget._watchers = []);
vm._widget._watchers = vm._widget._watchers.concat(watchers);
return;
}
if (BI.Widget.current) {
handler = watch;
watch = vm;
BI.Widget.current.$watchDelayCallbacks || (BI.Widget.current.$watchDelayCallbacks = []);

Loading…
Cancel
Save