Browse Source

无JIRA history.current 变成响应式

es6
zsmj 3 years ago
parent
commit
7362589fcc
  1. 146
      dist/fix/fix.js
  2. 1
      src/router/router.js

146
dist/fix/fix.js vendored

@ -135,8 +135,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;
@ -145,18 +145,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;
@ -295,7 +295,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) {
@ -311,7 +311,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,
@ -331,12 +331,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}
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) {
@ -354,7 +354,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); //得到其产品
@ -538,10 +538,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;
@ -788,53 +788,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
function defineReactive(obj, observer, shallow) {
var props = {};
var model = void 0;
// if (typeof Proxy === 'function') {
// const deps = {}, childObs = {}, cache = {}
// _.each(obj, function (val, key) {
// if (key in $$skipArray) {
// return
// }
// cache[key] = val
// const dep = deps[key] = (observer && observer['__dep' + key]) || new Dep()
// observer && (observer['__dep' + key] = dep)
// childObs[key] = !shallow && observe(val, observer, key)
// })
// return model = new Proxy(props, {
// has: function (target, key) {
// return key in obj;
// },
// get: function (target, key) {
// if (key in $$skipArray) {
// return target[key]
// }
// const value = cache[key]
// if (Dep.target) {
// deps[key].depend()
// if (childObs[key]) {
// childObs[key].dep.depend()
// if (_.isArray(value)) {
// dependArray(value)
// }
// }
// }
// return value
// },
// set: function (target, key, newVal) {
// if (key in $$skipArray) {
// return target[key] = newVal
// }
// const value = cache[key], dep = deps[key]
// if (newVal === value || (newVal !== newVal && value !== value)) {
// return newVal
// }
// cache[key] = newVal
// childObs[key] = !shallow && observe(newVal, observer, key)
// obj[key] = childObs[key] ? childObs[key].model : newVal
// notify(model, key, dep)
// return obj[key]
// }
// })
// }
_.each(obj, function (val, key) {
if (key in $$skipArray) {
return;
@ -878,6 +831,50 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return model = createViewModel$1(obj, props);
}
function defineReactiveProperty(obj, key, val, shallow) {
var dep = new Dep();
var configurable = isConfigurable(obj, key);
if (!configurable) {
return;
}
if (arguments.length === 2) {
val = obj[key];
}
var childOb = !shallow && observe(val);
Object.defineProperty(obj, key, {
enumerable: true,
configurable: true,
get: function reactiveGetter() {
var value = childOb ? childOb.model : val;
if (Dep.target) {
dep.depend();
if (childOb) {
childOb.dep.depend();
if (_.isArray(value)) {
dependArray(value);
}
}
}
return value;
},
set: function reactiveSetter(newVal) {
var value = childOb ? childOb.model : val;
if (newVal === value || newVal !== newVal && value !== value) {
return;
}
childOb = configurable && !shallow && observe(newVal);
val = newVal;
obj[key] = childOb ? childOb.model : newVal;
dep.notify();
}
});
}
/**
* Set a property on an object. Adds the new property and
* triggers change notification if the property doesn't
@ -1522,6 +1519,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
exports.observe = observe;
exports.notify = notify;
exports.defineReactive = defineReactive;
exports.defineReactiveProperty = defineReactiveProperty;
exports.set = set;
exports.freeze = freeze;
exports.del = del;

1
src/router/router.js

@ -3130,6 +3130,7 @@
routes: this.options.routes,
base: this.options.base,
});
Fix.defineReactiveProperty(BI.Router.$router.history, "current");
this.$router.beforeEach(function (to, from, next) {
if (to.matched.length === 0) {
//如果上级也未匹配到路由则跳转主页面,如果上级能匹配到则转上级路由

Loading…
Cancel
Save