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

feat(runtime): onShareAppMessage,props sync

上级 6d451bf3
...@@ -282,7 +282,7 @@ function initMocks (vm) { ...@@ -282,7 +282,7 @@ function initMocks (vm) {
function initHooks (mpOptions, hooks) { function initHooks (mpOptions, hooks) {
hooks.forEach(hook => { hooks.forEach(hook => {
mpOptions[hook] = function (args) { mpOptions[hook] = function (args) {
this.$vm.__call_hook(hook, args); return this.$vm.__call_hook(hook, args)
}; };
}); });
} }
...@@ -404,6 +404,14 @@ function processEventArgs (event, args = [], isCustom) { ...@@ -404,6 +404,14 @@ function processEventArgs (event, args = [], isCustom) {
const ONCE = '~'; const ONCE = '~';
const CUSTOM = '^'; const CUSTOM = '^';
function getTarget (obj, path) {
const parts = path.split('.');
if (parts.length === 1) {
return obj[parts[0]]
}
return getTarget(obj[parts[0]], parts.slice(1).join('.'))
}
function handleEvent (event) { function handleEvent (event) {
event = wrapper$1(event); event = wrapper$1(event);
...@@ -426,17 +434,27 @@ function handleEvent (event) { ...@@ -426,17 +434,27 @@ function handleEvent (event) {
if (eventsArray && eventType === type) { if (eventsArray && eventType === type) {
eventsArray.forEach(eventArray => { eventsArray.forEach(eventArray => {
const handler = this.$vm[eventArray[0]]; const methodName = eventArray[0];
if (!isFn(handler)) { if (methodName === '$set') { // prop.sync
throw new Error(` _vm.${eventArray[0]} is not a function`) const args = eventArray[1];
} if (args.length === 2) { // :title.sync="title"
if (isOnce) { this.$vm[args[0]] = event.detail[0];
if (handler.once) { } else if (args.length === 3) {
return this.$vm.$set(getTarget(this.$vm, args[0]), args[1], event.detail[0]);
}
} else {
const handler = this.$vm[methodName];
if (!isFn(handler)) {
throw new Error(` _vm.${methodName} is not a function`)
}
if (isOnce) {
if (handler.once) {
return
}
handler.once = true;
} }
handler.once = true; handler.apply(this.$vm, processEventArgs(event, eventArray[1], isCustom));
} }
handler.apply(this.$vm, processEventArgs(event, eventArray[1], isCustom));
}); });
} }
}); });
......
{ {
"name": "@dcloudio/uni-mp-weixin", "name": "@dcloudio/uni-mp-weixin",
"version": "0.0.916", "version": "0.0.918",
"description": "uni-app mp-weixin", "description": "uni-app mp-weixin",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
......
...@@ -19,7 +19,7 @@ export function initMocks (vm) { ...@@ -19,7 +19,7 @@ export function initMocks (vm) {
export function initHooks (mpOptions, hooks) { export function initHooks (mpOptions, hooks) {
hooks.forEach(hook => { hooks.forEach(hook => {
mpOptions[hook] = function (args) { mpOptions[hook] = function (args) {
this.$vm.__call_hook(hook, args) return this.$vm.__call_hook(hook, args)
} }
}) })
} }
...@@ -147,6 +147,14 @@ function processEventArgs (event, args = [], isCustom) { ...@@ -147,6 +147,14 @@ function processEventArgs (event, args = [], isCustom) {
const ONCE = '~' const ONCE = '~'
const CUSTOM = '^' const CUSTOM = '^'
function getTarget (obj, path) {
const parts = path.split('.')
if (parts.length === 1) {
return obj[parts[0]]
}
return getTarget(obj[parts[0]], parts.slice(1).join('.'))
}
export function handleEvent (event) { export function handleEvent (event) {
event = wrapper(event) event = wrapper(event)
...@@ -169,17 +177,27 @@ export function handleEvent (event) { ...@@ -169,17 +177,27 @@ export function handleEvent (event) {
if (eventsArray && eventType === type) { if (eventsArray && eventType === type) {
eventsArray.forEach(eventArray => { eventsArray.forEach(eventArray => {
const handler = this.$vm[eventArray[0]] const methodName = eventArray[0]
if (!isFn(handler)) { if (methodName === '$set') { // prop.sync
throw new Error(` _vm.${eventArray[0]} is not a function`) const args = eventArray[1]
} if (args.length === 2) { // :title.sync="title"
if (isOnce) { this.$vm[args[0]] = event.detail[0]
if (handler.once) { } else if (args.length === 3) {
return this.$vm.$set(getTarget(this.$vm, args[0]), args[1], event.detail[0])
}
} else {
const handler = this.$vm[methodName]
if (!isFn(handler)) {
throw new Error(` _vm.${methodName} is not a function`)
}
if (isOnce) {
if (handler.once) {
return
}
handler.once = true
} }
handler.once = true handler.apply(this.$vm, processEventArgs(event, eventArray[1], isCustom))
} }
handler.apply(this.$vm, processEventArgs(event, eventArray[1], isCustom))
}) })
} }
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册