提交 cff9dd64 编写于 作者: Q qiang

fix(mp): App instance maybe no triggerEvent method

上级 d082e804
...@@ -2230,17 +2230,17 @@ function updateListeners ( ...@@ -2230,17 +2230,17 @@ function updateListeners (
/* */ /* */
// fixed by xxxxxx (mp properties) // fixed by xxxxxx (mp properties)
function extractPropertiesFromVNodeData(data, Ctor, res, context) { function extractPropertiesFromVNodeData(data, Ctor, res, context) {
var propOptions = Ctor.options.mpOptions && Ctor.options.mpOptions.properties; var propOptions = Ctor.options.mpOptions && Ctor.options.mpOptions.properties;
if (isUndef(propOptions)) { if (isUndef(propOptions)) {
return res return res
} }
var externalClasses = Ctor.options.mpOptions.externalClasses || []; var externalClasses = Ctor.options.mpOptions.externalClasses || [];
var attrs = data.attrs; var attrs = data.attrs;
var props = data.props; var props = data.props;
if (isDef(attrs) || isDef(props)) { if (isDef(attrs) || isDef(props)) {
for (var key in propOptions) { for (var key in propOptions) {
var altKey = hyphenate(key); var altKey = hyphenate(key);
var result = checkProp(res, props, key, altKey, true) || var result = checkProp(res, props, key, altKey, true) ||
checkProp(res, attrs, key, altKey, false); checkProp(res, attrs, key, altKey, false);
...@@ -2253,10 +2253,10 @@ function extractPropertiesFromVNodeData(data, Ctor, res, context) { ...@@ -2253,10 +2253,10 @@ function extractPropertiesFromVNodeData(data, Ctor, res, context) {
) { ) {
// 赋值 externalClass 真正的值(模板里 externalClass 的值可能是字符串) // 赋值 externalClass 真正的值(模板里 externalClass 的值可能是字符串)
res[key] = context[camelize(res[key])]; res[key] = context[camelize(res[key])];
} }
} }
} }
return res return res
} }
function extractPropsFromVNodeData ( function extractPropsFromVNodeData (
...@@ -5522,138 +5522,138 @@ function type(obj) { ...@@ -5522,138 +5522,138 @@ function type(obj) {
return Object.prototype.toString.call(obj) return Object.prototype.toString.call(obj)
} }
/* */ /* */
function flushCallbacks$1(vm) { function flushCallbacks$1(vm) {
if (vm.__next_tick_callbacks && vm.__next_tick_callbacks.length) { if (vm.__next_tick_callbacks && vm.__next_tick_callbacks.length) {
if (process.env.VUE_APP_DEBUG) { if (process.env.VUE_APP_DEBUG) {
var mpInstance = vm.$scope; var mpInstance = vm.$scope;
console.log('[' + (+new Date) + '][' + (mpInstance.is || mpInstance.route) + '][' + vm._uid + console.log('[' + (+new Date) + '][' + (mpInstance.is || mpInstance.route) + '][' + vm._uid +
']:flushCallbacks[' + vm.__next_tick_callbacks.length + ']'); ']:flushCallbacks[' + vm.__next_tick_callbacks.length + ']');
} }
var copies = vm.__next_tick_callbacks.slice(0); var copies = vm.__next_tick_callbacks.slice(0);
vm.__next_tick_callbacks.length = 0; vm.__next_tick_callbacks.length = 0;
for (var i = 0; i < copies.length; i++) { for (var i = 0; i < copies.length; i++) {
copies[i](); copies[i]();
} }
} }
} }
function hasRenderWatcher(vm) { function hasRenderWatcher(vm) {
return queue.find(function (watcher) { return vm._watcher === watcher; }) return queue.find(function (watcher) { return vm._watcher === watcher; })
} }
function nextTick$1(vm, cb) { function nextTick$1(vm, cb) {
//1.nextTick 之前 已 setData 且 setData 还未回调完成 //1.nextTick 之前 已 setData 且 setData 还未回调完成
//2.nextTick 之前存在 render watcher //2.nextTick 之前存在 render watcher
if (!vm.__next_tick_pending && !hasRenderWatcher(vm)) { if (!vm.__next_tick_pending && !hasRenderWatcher(vm)) {
if(process.env.VUE_APP_DEBUG){ if(process.env.VUE_APP_DEBUG){
var mpInstance = vm.$scope; var mpInstance = vm.$scope;
console.log('[' + (+new Date) + '][' + (mpInstance.is || mpInstance.route) + '][' + vm._uid + console.log('[' + (+new Date) + '][' + (mpInstance.is || mpInstance.route) + '][' + vm._uid +
']:nextVueTick'); ']:nextVueTick');
} }
return nextTick(cb, vm) return nextTick(cb, vm)
}else{ }else{
if(process.env.VUE_APP_DEBUG){ if(process.env.VUE_APP_DEBUG){
var mpInstance$1 = vm.$scope; var mpInstance$1 = vm.$scope;
console.log('[' + (+new Date) + '][' + (mpInstance$1.is || mpInstance$1.route) + '][' + vm._uid + console.log('[' + (+new Date) + '][' + (mpInstance$1.is || mpInstance$1.route) + '][' + vm._uid +
']:nextMPTick'); ']:nextMPTick');
} }
} }
var _resolve; var _resolve;
if (!vm.__next_tick_callbacks) { if (!vm.__next_tick_callbacks) {
vm.__next_tick_callbacks = []; vm.__next_tick_callbacks = [];
} }
vm.__next_tick_callbacks.push(function () { vm.__next_tick_callbacks.push(function () {
if (cb) { if (cb) {
try { try {
cb.call(vm); cb.call(vm);
} catch (e) { } catch (e) {
handleError(e, vm, 'nextTick'); handleError(e, vm, 'nextTick');
} }
} else if (_resolve) { } else if (_resolve) {
_resolve(vm); _resolve(vm);
} }
}); });
// $flow-disable-line // $flow-disable-line
if (!cb && typeof Promise !== 'undefined') { if (!cb && typeof Promise !== 'undefined') {
return new Promise(function (resolve) { return new Promise(function (resolve) {
_resolve = resolve; _resolve = resolve;
}) })
} }
} }
/* */ /* */
function cloneWithData(vm) { function cloneWithData(vm) {
// 确保当前 vm 所有数据被同步 // 确保当前 vm 所有数据被同步
var ret = Object.create(null); var ret = Object.create(null);
var dataKeys = [].concat( var dataKeys = [].concat(
Object.keys(vm._data || {}), Object.keys(vm._data || {}),
Object.keys(vm._computedWatchers || {})); Object.keys(vm._computedWatchers || {}));
dataKeys.reduce(function(ret, key) { dataKeys.reduce(function(ret, key) {
ret[key] = vm[key]; ret[key] = vm[key];
return ret return ret
}, ret); }, ret);
// vue-composition-api // vue-composition-api
var compositionApiState = vm.__composition_api_state__ || vm.__secret_vfa_state__; var compositionApiState = vm.__composition_api_state__ || vm.__secret_vfa_state__;
var rawBindings = compositionApiState && compositionApiState.rawBindings; var rawBindings = compositionApiState && compositionApiState.rawBindings;
if (rawBindings) { if (rawBindings) {
Object.keys(rawBindings).forEach(function (key) { Object.keys(rawBindings).forEach(function (key) {
ret[key] = vm[key]; ret[key] = vm[key];
}); });
} }
//TODO 需要把无用数据处理掉,比如 list=>l0 则 list 需要移除,否则多传输一份数据 //TODO 需要把无用数据处理掉,比如 list=>l0 则 list 需要移除,否则多传输一份数据
Object.assign(ret, vm.$mp.data || {}); Object.assign(ret, vm.$mp.data || {});
if ( if (
Array.isArray(vm.$options.behaviors) && Array.isArray(vm.$options.behaviors) &&
vm.$options.behaviors.indexOf('uni://form-field') !== -1 vm.$options.behaviors.indexOf('uni://form-field') !== -1
) { //form-field ) { //form-field
ret['name'] = vm.name; ret['name'] = vm.name;
ret['value'] = vm.value; ret['value'] = vm.value;
} }
return JSON.parse(JSON.stringify(ret)) return JSON.parse(JSON.stringify(ret))
} }
var patch = function(oldVnode, vnode) { var patch = function(oldVnode, vnode) {
var this$1 = this; var this$1 = this;
if (vnode === null) { //destroy if (vnode === null) { //destroy
return return
} }
if (this.mpType === 'page' || this.mpType === 'component') { if (this.mpType === 'page' || this.mpType === 'component') {
var mpInstance = this.$scope; var mpInstance = this.$scope;
var data = Object.create(null); var data = Object.create(null);
try { try {
data = cloneWithData(this); data = cloneWithData(this);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
data.__webviewId__ = mpInstance.data.__webviewId__; data.__webviewId__ = mpInstance.data.__webviewId__;
var mpData = Object.create(null); var mpData = Object.create(null);
Object.keys(data).forEach(function (key) { //仅同步 data 中有的数据 Object.keys(data).forEach(function (key) { //仅同步 data 中有的数据
mpData[key] = mpInstance.data[key]; mpData[key] = mpInstance.data[key];
}); });
var diffData = this.$shouldDiffData === false ? data : diff(data, mpData); var diffData = this.$shouldDiffData === false ? data : diff(data, mpData);
if (Object.keys(diffData).length) { if (Object.keys(diffData).length) {
if (process.env.VUE_APP_DEBUG) { if (process.env.VUE_APP_DEBUG) {
console.log('[' + (+new Date) + '][' + (mpInstance.is || mpInstance.route) + '][' + this._uid + console.log('[' + (+new Date) + '][' + (mpInstance.is || mpInstance.route) + '][' + this._uid +
']差量更新', ']差量更新',
JSON.stringify(diffData)); JSON.stringify(diffData));
} }
this.__next_tick_pending = true; this.__next_tick_pending = true;
mpInstance.setData(diffData, function () { mpInstance.setData(diffData, function () {
this$1.__next_tick_pending = false; this$1.__next_tick_pending = false;
flushCallbacks$1(this$1); flushCallbacks$1(this$1);
}); });
} else { } else {
flushCallbacks$1(this); flushCallbacks$1(this);
} }
} }
}; };
/* */ /* */
...@@ -5794,253 +5794,256 @@ function normalizeStyleBinding (bindingStyle) { ...@@ -5794,253 +5794,256 @@ function normalizeStyleBinding (bindingStyle) {
return bindingStyle return bindingStyle
} }
/* */ /* */
var MP_METHODS = ['createSelectorQuery', 'createIntersectionObserver', 'selectAllComponents', 'selectComponent']; var MP_METHODS = ['createSelectorQuery', 'createIntersectionObserver', 'selectAllComponents', 'selectComponent'];
function getTarget(obj, path) { function getTarget(obj, path) {
var parts = path.split('.'); var parts = path.split('.');
var key = parts[0]; var key = parts[0];
if (key.indexOf('__$n') === 0) { //number index if (key.indexOf('__$n') === 0) { //number index
key = parseInt(key.replace('__$n', '')); key = parseInt(key.replace('__$n', ''));
} }
if (parts.length === 1) { if (parts.length === 1) {
return obj[key] return obj[key]
} }
return getTarget(obj[key], parts.slice(1).join('.')) return getTarget(obj[key], parts.slice(1).join('.'))
} }
function internalMixin(Vue) { function internalMixin(Vue) {
Vue.config.errorHandler = function(err, vm, info) { Vue.config.errorHandler = function(err, vm, info) {
Vue.util.warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); Vue.util.warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm);
console.error(err); console.error(err);
/* eslint-disable no-undef */ /* eslint-disable no-undef */
var app = typeof getApp === 'function' && getApp(); var app = typeof getApp === 'function' && getApp();
if (app && app.onError) { if (app && app.onError) {
app.onError(err); app.onError(err);
} }
}; };
var oldEmit = Vue.prototype.$emit; var oldEmit = Vue.prototype.$emit;
Vue.prototype.$emit = function(event) { Vue.prototype.$emit = function(event) {
if (this.$scope && event) { if (this.$scope && event) {
(this.$scope['_triggerEvent'] || this.$scope['triggerEvent']).call(this.$scope, event, { var triggerEvent = this.$scope['_triggerEvent'] || this.$scope['triggerEvent'];
__args__: toArray(arguments, 1) if (triggerEvent) {
}); triggerEvent.call(this.$scope, event, {
} __args__: toArray(arguments, 1)
return oldEmit.apply(this, arguments) });
}; }
}
Vue.prototype.$nextTick = function(fn) { return oldEmit.apply(this, arguments)
return nextTick$1(this, fn) };
};
Vue.prototype.$nextTick = function(fn) {
MP_METHODS.forEach(function (method) { return nextTick$1(this, fn)
Vue.prototype[method] = function(args) { };
if (this.$scope && this.$scope[method]) {
return this.$scope[method](args) MP_METHODS.forEach(function (method) {
} Vue.prototype[method] = function(args) {
// mp-alipay if (this.$scope && this.$scope[method]) {
if (typeof my === 'undefined') { return this.$scope[method](args)
return }
} // mp-alipay
if (method === 'createSelectorQuery') { if (typeof my === 'undefined') {
/* eslint-disable no-undef */ return
return my.createSelectorQuery(args) }
} else if (method === 'createIntersectionObserver') { if (method === 'createSelectorQuery') {
/* eslint-disable no-undef */ /* eslint-disable no-undef */
return my.createIntersectionObserver(args) return my.createSelectorQuery(args)
} } else if (method === 'createIntersectionObserver') {
// TODO mp-alipay 暂不支持 selectAllComponents,selectComponent /* eslint-disable no-undef */
}; return my.createIntersectionObserver(args)
}); }
// TODO mp-alipay 暂不支持 selectAllComponents,selectComponent
Vue.prototype.__init_provide = initProvide; };
});
Vue.prototype.__init_injections = initInjections;
Vue.prototype.__init_provide = initProvide;
Vue.prototype.__call_hook = function(hook, args) {
var vm = this; Vue.prototype.__init_injections = initInjections;
// #7573 disable dep collection when invoking lifecycle hooks
pushTarget(); Vue.prototype.__call_hook = function(hook, args) {
var handlers = vm.$options[hook]; var vm = this;
var info = hook + " hook"; // #7573 disable dep collection when invoking lifecycle hooks
var ret; pushTarget();
if (handlers) { var handlers = vm.$options[hook];
for (var i = 0, j = handlers.length; i < j; i++) { var info = hook + " hook";
ret = invokeWithErrorHandling(handlers[i], vm, args ? [args] : null, vm, info); var ret;
} if (handlers) {
} for (var i = 0, j = handlers.length; i < j; i++) {
if (vm._hasHookEvent) { ret = invokeWithErrorHandling(handlers[i], vm, args ? [args] : null, vm, info);
vm.$emit('hook:' + hook, args); }
} }
popTarget(); if (vm._hasHookEvent) {
return ret vm.$emit('hook:' + hook, args);
}; }
popTarget();
Vue.prototype.__set_model = function(target, key, value, modifiers) { return ret
if (Array.isArray(modifiers)) { };
if (modifiers.indexOf('trim') !== -1) {
value = value.trim(); Vue.prototype.__set_model = function(target, key, value, modifiers) {
} if (Array.isArray(modifiers)) {
if (modifiers.indexOf('number') !== -1) { if (modifiers.indexOf('trim') !== -1) {
value = this._n(value); value = value.trim();
} }
} if (modifiers.indexOf('number') !== -1) {
if (!target) { value = this._n(value);
target = this; }
} }
// 解决动态属性添加 if (!target) {
Vue.set(target, key, value); target = this;
}; }
// 解决动态属性添加
Vue.prototype.__set_sync = function(target, key, value) { Vue.set(target, key, value);
if (!target) { };
target = this;
} Vue.prototype.__set_sync = function(target, key, value) {
// 解决动态属性添加 if (!target) {
Vue.set(target, key, value); target = this;
}; }
// 解决动态属性添加
Vue.prototype.__get_orig = function(item) { Vue.set(target, key, value);
if (isPlainObject(item)) { };
return item['$orig'] || item
} Vue.prototype.__get_orig = function(item) {
return item if (isPlainObject(item)) {
}; return item['$orig'] || item
}
Vue.prototype.__get_value = function(dataPath, target) { return item
return getTarget(target || this, dataPath) };
};
Vue.prototype.__get_value = function(dataPath, target) {
return getTarget(target || this, dataPath)
Vue.prototype.__get_class = function(dynamicClass, staticClass) { };
return renderClass(staticClass, dynamicClass)
};
Vue.prototype.__get_class = function(dynamicClass, staticClass) {
Vue.prototype.__get_style = function(dynamicStyle, staticStyle) { return renderClass(staticClass, dynamicClass)
if (!dynamicStyle && !staticStyle) { };
return ''
} Vue.prototype.__get_style = function(dynamicStyle, staticStyle) {
var dynamicStyleObj = normalizeStyleBinding(dynamicStyle); if (!dynamicStyle && !staticStyle) {
var styleObj = staticStyle ? extend(staticStyle, dynamicStyleObj) : dynamicStyleObj; return ''
return Object.keys(styleObj).map(function (name) { return ((hyphenate(name)) + ":" + (styleObj[name])); }).join(';') }
}; var dynamicStyleObj = normalizeStyleBinding(dynamicStyle);
var styleObj = staticStyle ? extend(staticStyle, dynamicStyleObj) : dynamicStyleObj;
Vue.prototype.__map = function(val, iteratee) { return Object.keys(styleObj).map(function (name) { return ((hyphenate(name)) + ":" + (styleObj[name])); }).join(';')
//TODO 暂不考虑 string };
var ret, i, l, keys, key;
if (Array.isArray(val)) { Vue.prototype.__map = function(val, iteratee) {
ret = new Array(val.length); //TODO 暂不考虑 string
for (i = 0, l = val.length; i < l; i++) { var ret, i, l, keys, key;
ret[i] = iteratee(val[i], i); if (Array.isArray(val)) {
} ret = new Array(val.length);
return ret for (i = 0, l = val.length; i < l; i++) {
} else if (isObject(val)) { ret[i] = iteratee(val[i], i);
keys = Object.keys(val); }
ret = Object.create(null); return ret
for (i = 0, l = keys.length; i < l; i++) { } else if (isObject(val)) {
key = keys[i]; keys = Object.keys(val);
ret[key] = iteratee(val[key], key, i); ret = Object.create(null);
} for (i = 0, l = keys.length; i < l; i++) {
return ret key = keys[i];
} else if (typeof val === 'number') { ret[key] = iteratee(val[key], key, i);
ret = new Array(val); }
for (i = 0, l = val; i < l; i++) { return ret
// 第一个参数暂时仍和小程序一致 } else if (typeof val === 'number') {
ret[i] = iteratee(i, i); ret = new Array(val);
} for (i = 0, l = val; i < l; i++) {
return ret // 第一个参数暂时仍和小程序一致
} ret[i] = iteratee(i, i);
return [] }
}; return ret
}
} return []
};
/* */
}
var LIFECYCLE_HOOKS$1 = [
//App /* */
'onLaunch',
'onShow', var LIFECYCLE_HOOKS$1 = [
'onHide', //App
'onUniNViewMessage', 'onLaunch',
'onPageNotFound', 'onShow',
'onThemeChange', 'onHide',
'onError', 'onUniNViewMessage',
'onUnhandledRejection', 'onPageNotFound',
//Page 'onThemeChange',
'onInit', 'onError',
'onLoad', 'onUnhandledRejection',
// 'onShow', //Page
'onReady', 'onInit',
// 'onHide', 'onLoad',
'onUnload', // 'onShow',
'onPullDownRefresh', 'onReady',
'onReachBottom', // 'onHide',
'onTabItemTap', 'onUnload',
'onAddToFavorites', 'onPullDownRefresh',
'onShareTimeline', 'onReachBottom',
'onShareAppMessage', 'onTabItemTap',
'onResize', 'onAddToFavorites',
'onPageScroll', 'onShareTimeline',
'onNavigationBarButtonTap', 'onShareAppMessage',
'onBackPress', 'onResize',
'onNavigationBarSearchInputChanged', 'onPageScroll',
'onNavigationBarSearchInputConfirmed', 'onNavigationBarButtonTap',
'onNavigationBarSearchInputClicked', 'onBackPress',
//Component 'onNavigationBarSearchInputChanged',
// 'onReady', // 兼容旧版本,应该移除该事件 'onNavigationBarSearchInputConfirmed',
'onPageShow', 'onNavigationBarSearchInputClicked',
'onPageHide', //Component
'onPageResize', // 'onReady', // 兼容旧版本,应该移除该事件
'onUploadDouyinVideo' 'onPageShow',
]; 'onPageHide',
function lifecycleMixin$1(Vue) { 'onPageResize',
'onUploadDouyinVideo'
//fixed vue-class-component ];
var oldExtend = Vue.extend; function lifecycleMixin$1(Vue) {
Vue.extend = function(extendOptions) {
extendOptions = extendOptions || {}; //fixed vue-class-component
var oldExtend = Vue.extend;
var methods = extendOptions.methods; Vue.extend = function(extendOptions) {
if (methods) { extendOptions = extendOptions || {};
Object.keys(methods).forEach(function (methodName) {
if (LIFECYCLE_HOOKS$1.indexOf(methodName)!==-1) { var methods = extendOptions.methods;
extendOptions[methodName] = methods[methodName]; if (methods) {
delete methods[methodName]; Object.keys(methods).forEach(function (methodName) {
} if (LIFECYCLE_HOOKS$1.indexOf(methodName)!==-1) {
}); extendOptions[methodName] = methods[methodName];
} delete methods[methodName];
}
return oldExtend.call(this, extendOptions) });
}; }
var strategies = Vue.config.optionMergeStrategies; return oldExtend.call(this, extendOptions)
var mergeHook = strategies.created; };
LIFECYCLE_HOOKS$1.forEach(function (hook) {
strategies[hook] = mergeHook; var strategies = Vue.config.optionMergeStrategies;
}); var mergeHook = strategies.created;
LIFECYCLE_HOOKS$1.forEach(function (hook) {
Vue.prototype.__lifecycle_hooks__ = LIFECYCLE_HOOKS$1; strategies[hook] = mergeHook;
} });
/* */ Vue.prototype.__lifecycle_hooks__ = LIFECYCLE_HOOKS$1;
}
// install platform patch function
Vue.prototype.__patch__ = patch; /* */
// public mount method // install platform patch function
Vue.prototype.$mount = function( Vue.prototype.__patch__ = patch;
el ,
hydrating // public mount method
) { Vue.prototype.$mount = function(
return mountComponent$1(this, el, hydrating) el ,
}; hydrating
) {
lifecycleMixin$1(Vue); return mountComponent$1(this, el, hydrating)
};
lifecycleMixin$1(Vue);
internalMixin(Vue); internalMixin(Vue);
/* */ /* */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册