use object format modifiers

This commit is contained in:
Evan You 2016-04-12 20:38:03 -04:00
parent 9af0745779
commit 4ea6ae3177
4 changed files with 11 additions and 11 deletions

View File

@ -22,9 +22,8 @@ const modifierCode = {
export function addHandler (events, name, value, modifiers) {
// check capture modifier
const captureIndex = modifiers && modifiers.indexOf('capture')
if (captureIndex > -1) {
modifiers.splice(captureIndex, 1)
if (modifiers && modifiers.capture) {
delete modifiers.capture
name = '!' + name // mark the event as captured
}
const newHandler = { value, modifiers }
@ -51,18 +50,17 @@ function genHandler (handler) {
return 'function(){}'
} else if (isArray(handler)) {
return `[${handler.map(genHandler).join(',')}]`
} else if (!handler.modifiers || !handler.modifiers.length) {
} else if (!handler.modifiers) {
return simplePathRE.test(handler.value)
? handler.value
: `function($event){${handler.value}}`
} else {
let code = 'function($event){'
for (let i = 0; i < handler.modifiers.length; i++) {
let modifier = handler.modifiers[i]
code += modifierCode[modifier] || genKeyFilter(modifier)
for (let key in handler.modifiers) {
code += modifierCode[key] || genKeyFilter(key)
}
let handlerCode = simplePathRE.test(handler.value)
? handler.value + '()'
? handler.value + '($event)'
: handler.value
return code + handlerCode + '}'
}

View File

@ -17,7 +17,9 @@ const modifierRE = /\.[^\.]+/g
export function parseModifiers (name) {
const match = name.match(modifierRE)
if (match) {
return match.map(m => m.slice(1))
const ret = {}
match.forEach(m => { ret[m.slice(1)] = true })
return ret
}
}

View File

@ -111,7 +111,7 @@ function genData (el, key) {
addHandler(events, name, value, modifiers)
} else if (name === 'v-model') {
hasProps = hasEvents = true
props += genModel(el, events, value) + ','
props += genModel(el, events, value, modifiers) + ','
} else {
// TODO: normal directives
}

View File

@ -1,6 +1,6 @@
import { addHandler } from './events'
export function genModel (el, events, value) {
export function genModel (el, events, value, modifiers) {
if (el.tag === 'select') {
if (el.attrsMap.multiple != null) {
return genMultiSelect(events, value, el)