|
|
@ -134,8 +134,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
setImmediate(nextTickHandler); |
|
|
|
setImmediate(nextTickHandler); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else if (typeof MessageChannel !== 'undefined' && (isNative(MessageChannel) || |
|
|
|
} else if (typeof MessageChannel !== 'undefined' && (isNative(MessageChannel) || |
|
|
|
// PhantomJS
|
|
|
|
// PhantomJS
|
|
|
|
MessageChannel.toString() === '[object MessageChannelConstructor]')) { |
|
|
|
MessageChannel.toString() === '[object MessageChannelConstructor]')) { |
|
|
|
var channel = new MessageChannel(); |
|
|
|
var channel = new MessageChannel(); |
|
|
|
var port = channel.port2; |
|
|
|
var port = channel.port2; |
|
|
|
channel.port1.onmessage = nextTickHandler; |
|
|
|
channel.port1.onmessage = nextTickHandler; |
|
|
@ -144,18 +144,18 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else |
|
|
|
} else |
|
|
|
/* istanbul ignore next */ |
|
|
|
/* istanbul ignore next */ |
|
|
|
if (typeof Promise !== 'undefined' && isNative(Promise)) { |
|
|
|
if (typeof Promise !== 'undefined' && isNative(Promise)) { |
|
|
|
// use microtask in non-DOM environments, e.g. Weex
|
|
|
|
// use microtask in non-DOM environments, e.g. Weex
|
|
|
|
var p = Promise.resolve(); |
|
|
|
var p = Promise.resolve(); |
|
|
|
timerFunc = function timerFunc() { |
|
|
|
timerFunc = function timerFunc() { |
|
|
|
p.then(nextTickHandler); |
|
|
|
p.then(nextTickHandler); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// fallback to setTimeout
|
|
|
|
// fallback to setTimeout
|
|
|
|
timerFunc = function timerFunc() { |
|
|
|
timerFunc = function timerFunc() { |
|
|
|
setTimeout(nextTickHandler, 0); |
|
|
|
setTimeout(nextTickHandler, 0); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return function queueNextTick(cb, ctx) { |
|
|
|
return function queueNextTick(cb, ctx) { |
|
|
|
var _resolve = void 0; |
|
|
|
var _resolve = void 0; |
|
|
@ -294,7 +294,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
if (isIE9Below) { |
|
|
|
if (isIE9Below) { |
|
|
|
var VBClassPool = {}; |
|
|
|
var VBClassPool = {}; |
|
|
|
window.execScript([// jshint ignore:line
|
|
|
|
window.execScript([// jshint ignore:line
|
|
|
|
'Function parseVB(code)', '\tExecuteGlobal(code)', 'End Function' //转换一段文本为VB代码
|
|
|
|
'Function parseVB(code)', '\tExecuteGlobal(code)', 'End Function' //转换一段文本为VB代码
|
|
|
|
].join('\n'), 'VBScript'); |
|
|
|
].join('\n'), 'VBScript'); |
|
|
|
|
|
|
|
|
|
|
|
var VBMediator = function VBMediator(instance, accessors, name, value) { |
|
|
|
var VBMediator = function VBMediator(instance, accessors, name, value) { |
|
|
@ -310,7 +310,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
// jshint ignore:line
|
|
|
|
// jshint ignore:line
|
|
|
|
var buffer = []; |
|
|
|
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', //链式调用
|
|
|
|
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那样随意增删属性,必须在这里预先定义好
|
|
|
|
//添加普通属性,因为VBScript对象不能像JS那样随意增删属性,必须在这里预先定义好
|
|
|
|
var uniq = { |
|
|
|
var uniq = { |
|
|
|
$vbthis: true, |
|
|
|
$vbthis: true, |
|
|
@ -330,12 +330,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
} |
|
|
|
} |
|
|
|
uniq[name] = true; |
|
|
|
uniq[name] = true; |
|
|
|
buffer.push( |
|
|
|
buffer.push( |
|
|
|
//由于不知对方会传入什么,因此set, let都用上
|
|
|
|
//由于不知对方会传入什么,因此set, let都用上
|
|
|
|
'\tPublic Property Let [' + name + '](val' + timeBucket + ')', //setter
|
|
|
|
'\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 Set [' + name + '](val' + timeBucket + ')', //setter
|
|
|
|
'\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Get [' + name + ']', //getter
|
|
|
|
'\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Get [' + name + ']', //getter
|
|
|
|
'\tOn Error Resume Next', //必须优先使用set语句,否则它会误将数组当字符串返回
|
|
|
|
'\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'); |
|
|
|
'\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) { |
|
|
|
for (name in properties) { |
|
|
@ -353,7 +353,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
className = makeHashCode('VBClass'); |
|
|
|
className = makeHashCode('VBClass'); |
|
|
|
window.parseVB('Class ' + className + body); |
|
|
|
window.parseVB('Class ' + className + body); |
|
|
|
window.parseVB(['Function ' + className + 'Factory(acc, vbm)', //创建实例并传入两个关键的参数
|
|
|
|
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; |
|
|
|
VBClassPool[body] = className; |
|
|
|
} |
|
|
|
} |
|
|
|
var ret = window[className + 'Factory'](accessors, VBMediator); //得到其产品
|
|
|
|
var ret = window[className + 'Factory'](accessors, VBMediator); //得到其产品
|
|
|
@ -537,10 +537,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
if (this.active) { |
|
|
|
if (this.active) { |
|
|
|
var value = this.get(); |
|
|
|
var value = this.get(); |
|
|
|
if (value !== this.value || |
|
|
|
if (value !== this.value || |
|
|
|
// Deep watchers and watchers on Object/Arrays should fire even
|
|
|
|
// Deep watchers and watchers on Object/Arrays should fire even
|
|
|
|
// when the value is the same, because the value may
|
|
|
|
// when the value is the same, because the value may
|
|
|
|
// have mutated.
|
|
|
|
// have mutated.
|
|
|
|
_.isObject(value) && options && options.refresh || this.deep) { |
|
|
|
_.isObject(value) && options && options.refresh || this.deep) { |
|
|
|
// set new value
|
|
|
|
// set new value
|
|
|
|
var oldValue = this.value; |
|
|
|
var oldValue = this.value; |
|
|
|
this.value = value; |
|
|
|
this.value = value; |
|
|
@ -630,8 +630,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
_.each(['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'], function (method) { |
|
|
|
_.each(['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'], function (method) { |
|
|
|
var original = arrayProto[method]; |
|
|
|
var original = arrayProto[method]; |
|
|
|
arrayMethods[method] = function mutator() { |
|
|
|
arrayMethods[method] = function mutator() { |
|
|
|
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
|
|
|
for (var _len = arguments.length, args = Array(_len), _key2 = 0; _key2 < _len; _key2++) { |
|
|
|
args[_key] = arguments[_key]; |
|
|
|
args[_key2] = arguments[_key2]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ob = this.__ob__; |
|
|
|
var ob = this.__ob__; |
|
|
@ -773,10 +773,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
root = parent; |
|
|
|
root = parent; |
|
|
|
parent = parent.parent; |
|
|
|
parent = parent.parent; |
|
|
|
} |
|
|
|
} |
|
|
|
for (var _key2 in root._globalDeps) { |
|
|
|
for (var _key in root._globalDeps) { |
|
|
|
var reg = new RegExp(_key2); |
|
|
|
var reg = new RegExp(_key); |
|
|
|
if (reg.test(route)) { |
|
|
|
if (reg.test(route)) { |
|
|
|
root._globalDeps[_key2].notify({ observer: observer, key: _key2 }); |
|
|
|
for (var i = 0; i < root._globalDeps[_key].length; i++) { |
|
|
|
|
|
|
|
root._globalDeps[_key][i].notify({ observer: observer, key: _key }); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -958,7 +960,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function routeToRegExp(route) { |
|
|
|
function routeToRegExp(route) { |
|
|
|
route = route.replace(/\*./g, '[a-zA-Z0-9_]+.'); |
|
|
|
route = route.replace(/\*\*/g, '[a-zA-Z0-9_]+').replace(/\*./g, '[a-zA-Z0-9_]+.'); |
|
|
|
return '^' + route + '$'; |
|
|
|
return '^' + route + '$'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1047,21 +1049,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
}); |
|
|
|
}); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (/\*\*$|\*$/.test(exp)) { |
|
|
|
// **.a.**的情况,场景:a.b.c, 如果用b.**监听, a被重新赋值b上的_scopeDes就不存在了
|
|
|
|
throw new Error('not support'); |
|
|
|
if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) { |
|
|
|
} |
|
|
|
|
|
|
|
//其他含有*的情况,如*.a,*.*.a,a.*.a
|
|
|
|
|
|
|
|
if (/\*/.test(exp)) { |
|
|
|
|
|
|
|
var currentModel = model; |
|
|
|
|
|
|
|
//先获取到能获取到的对象
|
|
|
|
//先获取到能获取到的对象
|
|
|
|
var paths = exp.split("."); |
|
|
|
var paths = exp.split("."); |
|
|
|
for (var _i = 0, len = paths.length; _i < len; _i++) { |
|
|
|
var currentModel = model[paths[1]]; |
|
|
|
if (paths[_i] === "*") { |
|
|
|
exp = paths[1] + ".**"; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
currentModel = model[paths[_i]]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
exp = exp.substr(exp.indexOf("*")); |
|
|
|
|
|
|
|
//补全路径
|
|
|
|
//补全路径
|
|
|
|
var parent = currentModel.__ob__.parent, |
|
|
|
var parent = currentModel.__ob__.parent, |
|
|
|
root = currentModel.__ob__; |
|
|
|
root = currentModel.__ob__; |
|
|
@ -1073,7 +1066,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
var regStr = routeToRegExp(exp); |
|
|
|
var regStr = routeToRegExp(exp); |
|
|
|
var _dep = new Dep(); |
|
|
|
var _dep = new Dep(); |
|
|
|
root._globalDeps || (root._globalDeps = {}); |
|
|
|
root._globalDeps || (root._globalDeps = {}); |
|
|
|
root._globalDeps[regStr] = _dep; |
|
|
|
if (_.isArray(root._globalDeps[regStr])) { |
|
|
|
|
|
|
|
root._globalDeps[regStr].push(_dep); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
root._globalDeps[regStr] = [_dep]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var _w = new Watcher(currentModel, function () { |
|
|
|
var _w = new Watcher(currentModel, function () { |
|
|
|
_dep.depend(); |
|
|
|
_dep.depend(); |
|
|
@ -1082,8 +1079,64 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); |
|
|
|
callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); |
|
|
|
}, options); |
|
|
|
}, options); |
|
|
|
watchers.push(function unwatchFn() { |
|
|
|
watchers.push(function unwatchFn() { |
|
|
|
_w.teardown(); |
|
|
|
if (root._globalDeps) { |
|
|
|
root._globalDeps && delete root._globalDeps[regStr]; |
|
|
|
remove(root._globalDeps[regStr], _dep); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (root._globalDeps[regStr].length === 0) { |
|
|
|
|
|
|
|
delete root._globalDeps[regStr]; |
|
|
|
|
|
|
|
_w.teardown() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (/\*\*$|\*$/.test(exp)) { |
|
|
|
|
|
|
|
throw new Error('not support'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//其他含有*的情况,如*.a,*.*.a,a.*.a
|
|
|
|
|
|
|
|
if (/\*/.test(exp)) { |
|
|
|
|
|
|
|
var _currentModel = model; |
|
|
|
|
|
|
|
//先获取到能获取到的对象
|
|
|
|
|
|
|
|
var _paths = exp.split("."); |
|
|
|
|
|
|
|
for (var _i = 0, len = _paths.length; _i < len; _i++) { |
|
|
|
|
|
|
|
if (_paths[_i] === "*") { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_currentModel = model[_paths[_i]]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
exp = exp.substr(exp.indexOf("*")); |
|
|
|
|
|
|
|
//补全路径
|
|
|
|
|
|
|
|
var _parent = _currentModel.__ob__.parent, |
|
|
|
|
|
|
|
_root = _currentModel.__ob__; |
|
|
|
|
|
|
|
while (_parent) { |
|
|
|
|
|
|
|
exp = '*.' + exp; |
|
|
|
|
|
|
|
_root = _parent; |
|
|
|
|
|
|
|
_parent = _parent.parent; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var _regStr = routeToRegExp(exp); |
|
|
|
|
|
|
|
var _dep2 = new Dep(); |
|
|
|
|
|
|
|
_root._globalDeps || (_root._globalDeps = {}); |
|
|
|
|
|
|
|
if (_.isArray(_root._globalDeps[_regStr])) { |
|
|
|
|
|
|
|
_root._globalDeps[_regStr].push(_dep2); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_root._globalDeps[_regStr] = [_dep2]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _w2 = new Watcher(_currentModel, function () { |
|
|
|
|
|
|
|
_dep2.depend(); |
|
|
|
|
|
|
|
return NaN; |
|
|
|
|
|
|
|
}, function (newValue, oldValue, attrs) { |
|
|
|
|
|
|
|
callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); |
|
|
|
|
|
|
|
}, options); |
|
|
|
|
|
|
|
watchers.push(function unwatchFn() { |
|
|
|
|
|
|
|
if (_root._globalDeps) { |
|
|
|
|
|
|
|
remove(_root._globalDeps[_regStr], _dep2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (root._globalDeps[regStr].length === 0) { |
|
|
|
|
|
|
|
delete root._globalDeps[regStr]; |
|
|
|
|
|
|
|
_w.teardown() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|