提交 e8f11e25 编写于 作者: fxy060608's avatar fxy060608

fix(v3): JSON.stringify(undefined=>'')

上级 c34022d8
...@@ -8557,7 +8557,9 @@ var serviceContext = (function () { ...@@ -8557,7 +8557,9 @@ var serviceContext = (function () {
}); });
function publishHandler (eventType, args, pageIds) { function publishHandler (eventType, args, pageIds) {
args = JSON.stringify(args); args = JSON.stringify(args, (k, v) => { // 将 undefined 格式化为空字符串
return typeof v === 'undefined' ? '' : v
});
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log(`UNIAPP[publishHandler]:[${+new Date()}]`, eventType, args, pageIds); console.log(`UNIAPP[publishHandler]:[${+new Date()}]`, eventType, args, pageIds);
} }
...@@ -8949,12 +8951,12 @@ var serviceContext = (function () { ...@@ -8949,12 +8951,12 @@ var serviceContext = (function () {
}; };
} }
function noop() {} function noop () {}
const callbacks$a = []; // 数据同步 callback const callbacks$a = []; // 数据同步 callback
class VDomSync { class VDomSync {
constructor(pageId, pagePath) { constructor (pageId, pagePath) {
this.pageId = pageId; this.pageId = pageId;
this.pagePath = pagePath; this.pagePath = pagePath;
this.batchData = []; this.batchData = [];
...@@ -8966,7 +8968,7 @@ var serviceContext = (function () { ...@@ -8966,7 +8968,7 @@ var serviceContext = (function () {
this._init(); this._init();
} }
_init() { _init () {
UniServiceJSBridge.subscribe(VD_SYNC_CALLBACK, () => { UniServiceJSBridge.subscribe(VD_SYNC_CALLBACK, () => {
const copies = callbacks$a.slice(0); const copies = callbacks$a.slice(0);
callbacks$a.length = 0; callbacks$a.length = 0;
...@@ -8993,43 +8995,43 @@ var serviceContext = (function () { ...@@ -8993,43 +8995,43 @@ var serviceContext = (function () {
}); });
} }
addMountedVm(vm) { addMountedVm (vm) {
vm._$mounted(); // 触发vd数据同步 vm._$mounted(); // 触发vd数据同步
this.addCallback(function mounted() { this.addCallback(function mounted () {
vm.__call_hook('mounted'); vm.__call_hook('mounted');
}); });
} }
addUpdatedVm(vm) { addUpdatedVm (vm) {
vm._$updated(); // 触发vd数据同步 vm._$updated(); // 触发vd数据同步
this.addCallback(function mounted() { this.addCallback(function mounted () {
vm.__call_hook('updated'); vm.__call_hook('updated');
}); });
} }
addCallback(callback) { addCallback (callback) {
isFn(callback) && callbacks$a.push(callback); isFn(callback) && callbacks$a.push(callback);
} }
getVm(id) { getVm (id) {
return this.vms[id] return this.vms[id]
} }
addVm(vm) { addVm (vm) {
this.vms[vm._$id] = vm; this.vms[vm._$id] = vm;
} }
removeVm(vm) { removeVm (vm) {
delete this.vms[vm._$id]; delete this.vms[vm._$id];
} }
addEvent(cid, nid, name, handler) { addEvent (cid, nid, name, handler) {
const cHandlers = this.handlers[cid] || (this.handlers[cid] = Object.create(null)); const cHandlers = this.handlers[cid] || (this.handlers[cid] = Object.create(null));
const nHandlers = cHandlers[nid] || (cHandlers[nid] = Object.create(null)); const nHandlers = cHandlers[nid] || (cHandlers[nid] = Object.create(null));
(nHandlers[name] || (nHandlers[name] = [])).push(handler); (nHandlers[name] || (nHandlers[name] = [])).push(handler);
} }
removeEvent(cid, nid, name, handler) { removeEvent (cid, nid, name, handler) {
const cHandlers = this.handlers[cid] || (this.handlers[cid] = Object.create(null)); const cHandlers = this.handlers[cid] || (this.handlers[cid] = Object.create(null));
const nHandlers = cHandlers[nid] || (cHandlers[nid] = Object.create(null)); const nHandlers = cHandlers[nid] || (cHandlers[nid] = Object.create(null));
const eHandlers = nHandlers[name]; const eHandlers = nHandlers[name];
...@@ -9041,11 +9043,11 @@ var serviceContext = (function () { ...@@ -9041,11 +9043,11 @@ var serviceContext = (function () {
} }
} }
push(type, nodeId, data) { push (type, nodeId, data) {
this.batchData.push([type, [nodeId, data]]); this.batchData.push([type, [nodeId, data]]);
} }
flush() { flush () {
if (!this.initialized) { if (!this.initialized) {
this.initialized = true; this.initialized = true;
this.batchData.push([PAGE_CREATED, [this.pageId, this.pagePath]]); this.batchData.push([PAGE_CREATED, [this.pageId, this.pagePath]]);
...@@ -9061,7 +9063,7 @@ var serviceContext = (function () { ...@@ -9061,7 +9063,7 @@ var serviceContext = (function () {
} }
} }
destroy() { destroy () {
this.batchData.length = 0; this.batchData.length = 0;
this.vms = Object.create(null); this.vms = Object.create(null);
this.initialized = false; this.initialized = false;
...@@ -9099,17 +9101,17 @@ var serviceContext = (function () { ...@@ -9099,17 +9101,17 @@ var serviceContext = (function () {
return result return result
} }
function initData(Vue) { function initData (Vue) {
Vue.prototype._$s = setData; Vue.prototype._$s = setData;
Vue.prototype._$i = setIfData; Vue.prototype._$i = setIfData;
Vue.prototype._$f = setForData; Vue.prototype._$f = setForData;
Vue.prototype._$e = setElseIfData; Vue.prototype._$e = setElseIfData;
Vue.prototype._$setData = function setData(type, data) { Vue.prototype._$setData = function setData (type, data) {
this._$vd.push(type, this._$id, data); this._$vd.push(type, this._$id, data);
}; };
Vue.prototype._$mounted = function mounted() { Vue.prototype._$mounted = function mounted () {
if (!this._$vd) { if (!this._$vd) {
return return
} }
...@@ -9122,7 +9124,7 @@ var serviceContext = (function () { ...@@ -9122,7 +9124,7 @@ var serviceContext = (function () {
} }
}; };
Vue.prototype._$updated = function updated() { Vue.prototype._$updated = function updated () {
if (!this._$vd) { if (!this._$vd) {
return return
} }
...@@ -9133,13 +9135,13 @@ var serviceContext = (function () { ...@@ -9133,13 +9135,13 @@ var serviceContext = (function () {
}; };
Object.defineProperty(Vue.prototype, '_$vd', { Object.defineProperty(Vue.prototype, '_$vd', {
get() { get () {
return this.$root._$vdomSync return this.$root._$vdomSync
} }
}); });
Vue.mixin({ Vue.mixin({
beforeCreate() { beforeCreate () {
if (this.$options.mpType) { if (this.$options.mpType) {
this.mpType = this.$options.mpType; this.mpType = this.$options.mpType;
} }
...@@ -9160,7 +9162,7 @@ var serviceContext = (function () { ...@@ -9160,7 +9162,7 @@ var serviceContext = (function () {
this._$newData = Object.create(null); this._$newData = Object.create(null);
} }
}, },
beforeUpdate() { beforeUpdate () {
if (!this._$vd) { if (!this._$vd) {
return return
} }
...@@ -9169,7 +9171,7 @@ var serviceContext = (function () { ...@@ -9169,7 +9171,7 @@ var serviceContext = (function () {
console.log(`[${this._$id}] beforeUpdate ` + Date.now()); console.log(`[${this._$id}] beforeUpdate ` + Date.now());
this._$newData = Object.create(null); this._$newData = Object.create(null);
}, },
beforeDestroy() { beforeDestroy () {
if (!this._$vd) { if (!this._$vd) {
return return
} }
...@@ -9179,7 +9181,7 @@ var serviceContext = (function () { ...@@ -9179,7 +9181,7 @@ var serviceContext = (function () {
}); });
} }
function setData(id, name, value) { function setData (id, name, value) {
const diffData = this._$newData[id] || (this._$newData[id] = {}); const diffData = this._$newData[id] || (this._$newData[id] = {});
if (typeof name !== 'string') { if (typeof name !== 'string') {
...@@ -9195,7 +9197,7 @@ var serviceContext = (function () { ...@@ -9195,7 +9197,7 @@ var serviceContext = (function () {
return (diffData[name] = value) return (diffData[name] = value)
} }
function setForData(id, value) { function setForData (id, value) {
const diffData = this._$newData[id] || (this._$newData[id] = {}); const diffData = this._$newData[id] || (this._$newData[id] = {});
const vForData = diffData['v-for'] || (diffData['v-for'] = []); const vForData = diffData['v-for'] || (diffData['v-for'] = []);
...@@ -9216,11 +9218,11 @@ var serviceContext = (function () { ...@@ -9216,11 +9218,11 @@ var serviceContext = (function () {
return key return key
} }
function setIfData(id, value) { function setIfData (id, value) {
return ((this._$newData[id] || (this._$newData[id] = {}))['v-if'] = value) return ((this._$newData[id] || (this._$newData[id] = {}))['v-if'] = value)
} }
function setElseIfData(id, value) { function setElseIfData (id, value) {
return ((this._$newData[id] || (this._$newData[id] = {}))['v-else-if'] = value) return ((this._$newData[id] || (this._$newData[id] = {}))['v-else-if'] = value)
} }
......
此差异已折叠。
...@@ -119,7 +119,8 @@ if (process.env.UNI_PLATFORM === 'app-plus') { ...@@ -119,7 +119,8 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
) { ) {
process.env.UNI_USING_V3 = true process.env.UNI_USING_V3 = true
platformOptions.usingComponents = true platformOptions.usingComponents = true
process.env.UNI_OUTPUT_TMP_DIR = '' process.env.UNI_OUTPUT_TMP_DIR = ''
isNVueCompiler = true // v3 目前仅支持 uni-app 模式
} }
if (platformOptions.nvueCompiler === 'uni-app') { if (platformOptions.nvueCompiler === 'uni-app') {
......
export function publishHandler (eventType, args, pageIds) { export function publishHandler (eventType, args, pageIds) {
args = JSON.stringify(args) args = JSON.stringify(args, (k, v) => { // 将 undefined 格式化为空字符串
return typeof v === 'undefined' ? '' : v
})
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log(`UNIAPP[publishHandler]:[${+new Date()}]`, eventType, args, pageIds) console.log(`UNIAPP[publishHandler]:[${+new Date()}]`, eventType, args, pageIds)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册