From 5e3c213cba5bc475d41954f2f10078c055ebb15d Mon Sep 17 00:00:00 2001 From: Hanks Date: Sat, 16 Sep 2017 13:13:23 +0800 Subject: [PATCH 1/6] feat($compiler): supports compiling v-bind to the weex native directive in recycle-list --- src/compiler/codegen/index.js | 11 +++++-- src/compiler/helpers.js | 2 +- .../compiler/modules/recycle-list/index.js | 2 ++ .../compiler/modules/recycle-list/text.js | 8 +++-- .../compiler/modules/recycle-list/v-bind.js | 31 +++++++++++++++++++ 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 src/platforms/weex/compiler/modules/recycle-list/v-bind.js diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index c1d35e3953d..f027b2aeec8 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -475,15 +475,22 @@ function genComponent ( })` } -function genProps (props: Array<{ name: string, value: string }>): string { +function genProps (props: Array<{ name: string, value: any }>): string { let res = '' for (let i = 0; i < props.length; i++) { const prop = props[i] - res += `"${prop.name}":${transformSpecialNewlines(prop.value)},` + res += `"${prop.name}":${generateValue(prop.value)},` } return res.slice(0, -1) } +function generateValue (value) { + if (typeof value === 'string') { + return transformSpecialNewlines(value) + } + return JSON.stringify(value) +} + // #3895, #4268 function transformSpecialNewlines (text: string): string { return text diff --git a/src/compiler/helpers.js b/src/compiler/helpers.js index 49d6d6ae39a..7ed3ae238db 100644 --- a/src/compiler/helpers.js +++ b/src/compiler/helpers.js @@ -19,7 +19,7 @@ export function addProp (el: ASTElement, name: string, value: string) { (el.props || (el.props = [])).push({ name, value }) } -export function addAttr (el: ASTElement, name: string, value: string) { +export function addAttr (el: ASTElement, name: string, value: any) { (el.attrs || (el.attrs = [])).push({ name, value }) } diff --git a/src/platforms/weex/compiler/modules/recycle-list/index.js b/src/platforms/weex/compiler/modules/recycle-list/index.js index 82cc6e8f605..0fe7bb138a3 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/index.js +++ b/src/platforms/weex/compiler/modules/recycle-list/index.js @@ -1,6 +1,7 @@ /* @flow */ import { transformText } from './text' +import { transformVBind } from './v-bind' let currentRecycleList = null @@ -22,6 +23,7 @@ function postTransformNode (el: ASTElement) { if (el.tag === 'text') { transformText(el) } + transformVBind(el) } if (el === currentRecycleList) { currentRecycleList = null diff --git a/src/platforms/weex/compiler/modules/recycle-list/text.js b/src/platforms/weex/compiler/modules/recycle-list/text.js index a950aff93a9..fb72c81b555 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/text.js +++ b/src/platforms/weex/compiler/modules/recycle-list/text.js @@ -16,7 +16,9 @@ function genText (node: ASTNode) { export function transformText (el: ASTElement) { // weex can only contain text, so the parser // always generates a single child. - addAttr(el, 'value', genText(el.children[0])) - el.children = [] - el.plain = false + if (el.children.length) { + addAttr(el, 'value', genText(el.children[0])) + el.children = [] + el.plain = false + } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-bind.js b/src/platforms/weex/compiler/modules/recycle-list/v-bind.js new file mode 100644 index 00000000000..62bb0ac6a21 --- /dev/null +++ b/src/platforms/weex/compiler/modules/recycle-list/v-bind.js @@ -0,0 +1,31 @@ +/* @flow */ + +import { getAndRemoveAttr, addAttr } from 'compiler/helpers' + +function isBindingAttr (name) { + return /^(v\-bind)?\:/.test(name) +} + +function parseRealName (name: string): string { + return name.replace(/^(v\-bind)?\:/, '') +} + +export function transformVBind (el: ASTElement) { + if (!el.attrsList.length) { + return + } + el.attrsList.forEach(attr => { + // console.log('is binding attr:', attr.name, isBindingAttr(attr.name)) + if (isBindingAttr(attr.name)) { + const realName: string = parseRealName(attr.name) + const binding = getAndRemoveAttr(el, attr.name) + if (el.attrs) { + el.attrs = el.attrs.filter(at => at.name !== realName) // omit duplicated + } + getAndRemoveAttr(el, realName) + addAttr(el, realName, { '@binding': binding }) + } + }) + el.hasBindings = false + // el.plain = true +} From c7b57e1769784d8d65fbded901735723d0607b46 Mon Sep 17 00:00:00 2001 From: Hanks Date: Sat, 16 Sep 2017 14:59:23 +0800 Subject: [PATCH 2/6] feat(compile): supports compiling v-if to the weex native directive --- flow/compiler.js | 6 ++-- .../compiler/modules/recycle-list/index.js | 4 ++- .../compiler/modules/recycle-list/v-bind.js | 19 +++++------- .../compiler/modules/recycle-list/v-if.js | 29 +++++++++++++++++++ 4 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 src/platforms/weex/compiler/modules/recycle-list/v-if.js diff --git a/flow/compiler.js b/flow/compiler.js index 673dc5b4a54..a49f24ec940 100644 --- a/flow/compiler.js +++ b/flow/compiler.js @@ -72,8 +72,8 @@ declare type ASTNode = ASTElement | ASTText | ASTExpression; declare type ASTElement = { type: 1; tag: string; - attrsList: Array<{ name: string; value: string }>; - attrsMap: { [key: string]: string | null }; + attrsList: Array<{ name: string; value: any }>; + attrsMap: { [key: string]: any }; parent: ASTElement | void; children: Array; @@ -84,7 +84,7 @@ declare type ASTElement = { hasBindings?: boolean; text?: string; - attrs?: Array<{ name: string; value: string }>; + attrs?: Array<{ name: string; value: any }>; props?: Array<{ name: string; value: string }>; plain?: boolean; pre?: true; diff --git a/src/platforms/weex/compiler/modules/recycle-list/index.js b/src/platforms/weex/compiler/modules/recycle-list/index.js index 0fe7bb138a3..bb9d438d462 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/index.js +++ b/src/platforms/weex/compiler/modules/recycle-list/index.js @@ -2,6 +2,7 @@ import { transformText } from './text' import { transformVBind } from './v-bind' +import { transformVIf } from './v-if' let currentRecycleList = null @@ -14,6 +15,8 @@ function preTransformNode (el: ASTElement) { function transformNode (el: ASTElement) { if (currentRecycleList) { // TODO + transformVIf(el) + transformVBind(el) } } @@ -23,7 +26,6 @@ function postTransformNode (el: ASTElement) { if (el.tag === 'text') { transformText(el) } - transformVBind(el) } if (el === currentRecycleList) { currentRecycleList = null diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-bind.js b/src/platforms/weex/compiler/modules/recycle-list/v-bind.js index 62bb0ac6a21..f7836c8c214 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +++ b/src/platforms/weex/compiler/modules/recycle-list/v-bind.js @@ -1,31 +1,26 @@ /* @flow */ +import { camelize } from 'shared/util' import { getAndRemoveAttr, addAttr } from 'compiler/helpers' -function isBindingAttr (name) { +function isBindingAttr (name: string): boolean { return /^(v\-bind)?\:/.test(name) } -function parseRealName (name: string): string { - return name.replace(/^(v\-bind)?\:/, '') +function parseAttrName (name: string): string { + return camelize(name.replace(/^(v\-bind)?\:/, '')) } export function transformVBind (el: ASTElement) { - if (!el.attrsList.length) { + if (!el.attrsList || !el.attrsList.length) { return } el.attrsList.forEach(attr => { - // console.log('is binding attr:', attr.name, isBindingAttr(attr.name)) if (isBindingAttr(attr.name)) { - const realName: string = parseRealName(attr.name) + const name: string = parseAttrName(attr.name) const binding = getAndRemoveAttr(el, attr.name) - if (el.attrs) { - el.attrs = el.attrs.filter(at => at.name !== realName) // omit duplicated - } - getAndRemoveAttr(el, realName) - addAttr(el, realName, { '@binding': binding }) + addAttr(el, name, { '@binding': binding }) } }) el.hasBindings = false - // el.plain = true } diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-if.js b/src/platforms/weex/compiler/modules/recycle-list/v-if.js new file mode 100644 index 00000000000..c21f70ad2f7 --- /dev/null +++ b/src/platforms/weex/compiler/modules/recycle-list/v-if.js @@ -0,0 +1,29 @@ +/* @flow */ + +import { getAndRemoveAttr, addAttr } from 'compiler/helpers' + +function isConditionAttr (name: string): boolean { + return /^v\-if|v\-else|v\-else\-if/.test(name) +} + +export function transformVIf (el: ASTElement) { + for (const attr in el.attrsMap) { + if (!isConditionAttr(attr)) { + continue + } + const binding = getAndRemoveAttr(el, attr) + switch (attr) { + case 'v-if': { + addAttr(el, '[[match]]', binding) + el.attrsMap['[[match]]'] = binding + el.attrsList.push({ name: '[[match]]', value: binding }) + delete el.attrsMap[attr] + delete el.if + delete el.ifConditions + break + } + + // TODO: support v-else and v-else-if + } + } +} From 874e07f63fb196d875c6f3b38d9103b973635e13 Mon Sep 17 00:00:00 2001 From: Hanks Date: Sat, 16 Sep 2017 15:30:32 +0800 Subject: [PATCH 3/6] feat($compiler): supports compiling v-for to the weex native directive --- .../compiler/modules/recycle-list/index.js | 2 ++ .../compiler/modules/recycle-list/v-for.js | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/platforms/weex/compiler/modules/recycle-list/v-for.js diff --git a/src/platforms/weex/compiler/modules/recycle-list/index.js b/src/platforms/weex/compiler/modules/recycle-list/index.js index bb9d438d462..4dd153c5e92 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/index.js +++ b/src/platforms/weex/compiler/modules/recycle-list/index.js @@ -3,6 +3,7 @@ import { transformText } from './text' import { transformVBind } from './v-bind' import { transformVIf } from './v-if' +import { transformVFor } from './v-for' let currentRecycleList = null @@ -16,6 +17,7 @@ function transformNode (el: ASTElement) { if (currentRecycleList) { // TODO transformVIf(el) + transformVFor(el) transformVBind(el) } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-for.js b/src/platforms/weex/compiler/modules/recycle-list/v-for.js new file mode 100644 index 00000000000..ab096cfded1 --- /dev/null +++ b/src/platforms/weex/compiler/modules/recycle-list/v-for.js @@ -0,0 +1,35 @@ +/* @flow */ + +import { addAttr } from 'compiler/helpers' + +function isVForAttr (name: string): boolean { + return /^v\-for/.test(name) +} + +export function transformVFor (el: ASTElement) { + for (const attr in el.attrsMap) { + if (!isVForAttr(attr)) { + continue + } + const desc: Object = { + '@expression': el.for, + '@alias': el.alias + } + if (el.iterator1) { + desc['@index'] = el.iterator1 + } + if (el.iterator2) { + desc['@key'] = el.iterator1 + desc['@index'] = el.iterator2 + } + addAttr(el, '[[repeat]]', desc) + el.attrsMap['[[repeat]]'] = desc + el.attrsList.push({ name: '[[repeat]]', value: desc }) + delete el.attrsMap[attr] + delete el.for + delete el.alias + delete el.key + delete el.iterator1 + delete el.iterator2 + } +} From ef49070af9c52c7f823881d5b6969f916c60ab41 Mon Sep 17 00:00:00 2001 From: Hanks Date: Sat, 16 Sep 2017 22:43:36 +0800 Subject: [PATCH 4/6] feat($compiler): compile weex native directives in preTransformNode --- src/compiler/parser/index.js | 2 +- .../compiler/modules/recycle-list/index.js | 9 ++-- .../compiler/modules/recycle-list/v-bind.js | 31 +++++++------ .../compiler/modules/recycle-list/v-for.js | 44 +++++++++---------- .../compiler/modules/recycle-list/v-if.js | 30 +++---------- 5 files changed, 49 insertions(+), 67 deletions(-) diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index 2e77e78018a..5f1cb108fe0 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -25,7 +25,7 @@ export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/ export const forIteratorRE = /\((\{[^}]*\}|[^,]*),([^,]*)(?:,([^,]*))?\)/ const argRE = /:(.*)$/ -const bindRE = /^:|^v-bind:/ +export const bindRE = /^:|^v-bind:/ const modifierRE = /\.[^.]+/g const decodeHTMLCached = cached(he.decode) diff --git a/src/platforms/weex/compiler/modules/recycle-list/index.js b/src/platforms/weex/compiler/modules/recycle-list/index.js index 4dd153c5e92..f6e67b639ed 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/index.js +++ b/src/platforms/weex/compiler/modules/recycle-list/index.js @@ -11,14 +11,17 @@ function preTransformNode (el: ASTElement) { if (el.tag === 'recycle-list') { currentRecycleList = el } + if (currentRecycleList) { + // TODO + transformVBind(el) + transformVIf(el) + transformVFor(el) + } } function transformNode (el: ASTElement) { if (currentRecycleList) { // TODO - transformVIf(el) - transformVFor(el) - transformVBind(el) } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-bind.js b/src/platforms/weex/compiler/modules/recycle-list/v-bind.js index f7836c8c214..425e7f67bf8 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +++ b/src/platforms/weex/compiler/modules/recycle-list/v-bind.js @@ -1,26 +1,25 @@ /* @flow */ import { camelize } from 'shared/util' -import { getAndRemoveAttr, addAttr } from 'compiler/helpers' - -function isBindingAttr (name: string): boolean { - return /^(v\-bind)?\:/.test(name) -} +import { bindRE } from 'compiler/parser/index' +import { getAndRemoveAttr } from 'compiler/helpers' function parseAttrName (name: string): string { - return camelize(name.replace(/^(v\-bind)?\:/, '')) + return camelize(name.replace(bindRE, '')) } export function transformVBind (el: ASTElement) { - if (!el.attrsList || !el.attrsList.length) { - return - } - el.attrsList.forEach(attr => { - if (isBindingAttr(attr.name)) { - const name: string = parseAttrName(attr.name) - const binding = getAndRemoveAttr(el, attr.name) - addAttr(el, name, { '@binding': binding }) + for (const attr in el.attrsMap) { + if (bindRE.test(attr)) { + const name: string = parseAttrName(attr) + const value = { + '@binding': getAndRemoveAttr(el, attr) + } + delete el.attrsMap[attr] + el.attrsMap[name] = value + el.attrsList.push({ name, value }) + // addAttr(el, name, value) + // el.hasBindings = false } - }) - el.hasBindings = false + } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-for.js b/src/platforms/weex/compiler/modules/recycle-list/v-for.js index ab096cfded1..2396e301085 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/v-for.js +++ b/src/platforms/weex/compiler/modules/recycle-list/v-for.js @@ -1,35 +1,31 @@ /* @flow */ -import { addAttr } from 'compiler/helpers' - -function isVForAttr (name: string): boolean { - return /^v\-for/.test(name) -} +import { forAliasRE, forIteratorRE } from 'compiler/parser/index' +import { getAndRemoveAttr } from 'compiler/helpers' export function transformVFor (el: ASTElement) { - for (const attr in el.attrsMap) { - if (!isVForAttr(attr)) { - continue - } + const exp = getAndRemoveAttr(el, 'v-for') + if (!exp) { + return + } + const inMatch = exp.match(forAliasRE) + if (inMatch) { + const alias = inMatch[1].trim() const desc: Object = { - '@expression': el.for, - '@alias': el.alias - } - if (el.iterator1) { - desc['@index'] = el.iterator1 + '@expression': inMatch[2].trim(), + '@alias': alias } - if (el.iterator2) { - desc['@key'] = el.iterator1 - desc['@index'] = el.iterator2 + const iteratorMatch = alias.match(forIteratorRE) + if (iteratorMatch) { + desc['@alias'] = iteratorMatch[1].trim() + desc['@index'] = iteratorMatch[2].trim() + if (iteratorMatch[3]) { + desc['@key'] = iteratorMatch[2].trim() + desc['@index'] = iteratorMatch[3].trim() + } } - addAttr(el, '[[repeat]]', desc) + delete el.attrsMap['v-for'] el.attrsMap['[[repeat]]'] = desc el.attrsList.push({ name: '[[repeat]]', value: desc }) - delete el.attrsMap[attr] - delete el.for - delete el.alias - delete el.key - delete el.iterator1 - delete el.iterator2 } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-if.js b/src/platforms/weex/compiler/modules/recycle-list/v-if.js index c21f70ad2f7..673fb09e7f2 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/v-if.js +++ b/src/platforms/weex/compiler/modules/recycle-list/v-if.js @@ -1,29 +1,13 @@ /* @flow */ -import { getAndRemoveAttr, addAttr } from 'compiler/helpers' - -function isConditionAttr (name: string): boolean { - return /^v\-if|v\-else|v\-else\-if/.test(name) -} +import { getAndRemoveAttr } from 'compiler/helpers' export function transformVIf (el: ASTElement) { - for (const attr in el.attrsMap) { - if (!isConditionAttr(attr)) { - continue - } - const binding = getAndRemoveAttr(el, attr) - switch (attr) { - case 'v-if': { - addAttr(el, '[[match]]', binding) - el.attrsMap['[[match]]'] = binding - el.attrsList.push({ name: '[[match]]', value: binding }) - delete el.attrsMap[attr] - delete el.if - delete el.ifConditions - break - } - - // TODO: support v-else and v-else-if - } + const exp = getAndRemoveAttr(el, 'v-if') + if (exp) { + el.attrsMap['[[match]]'] = exp + el.attrsList.push({ name: '[[match]]', value: exp }) + delete el.attrsMap['v-if'] } + // TODO: support v-else and v-else-if } From df84a5f3f48fd71024713b3c783e9e7ede092110 Mon Sep 17 00:00:00 2001 From: Hanks Date: Sun, 17 Sep 2017 00:04:05 +0800 Subject: [PATCH 5/6] feat($compiler): supports compiling v-else-if and v-else to the weex native directive --- .../compiler/modules/recycle-list/index.js | 6 +-- .../compiler/modules/recycle-list/v-for.js | 4 +- .../compiler/modules/recycle-list/v-if.js | 43 +++++++++++++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/platforms/weex/compiler/modules/recycle-list/index.js b/src/platforms/weex/compiler/modules/recycle-list/index.js index f6e67b639ed..323df23ae87 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/index.js +++ b/src/platforms/weex/compiler/modules/recycle-list/index.js @@ -7,15 +7,15 @@ import { transformVFor } from './v-for' let currentRecycleList = null -function preTransformNode (el: ASTElement) { +function preTransformNode (el: ASTElement, options: CompilerOptions) { if (el.tag === 'recycle-list') { currentRecycleList = el } if (currentRecycleList) { // TODO transformVBind(el) - transformVIf(el) - transformVFor(el) + transformVIf(el, options) // and v-else-if and v-else + transformVFor(el, options) } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-for.js b/src/platforms/weex/compiler/modules/recycle-list/v-for.js index 2396e301085..29e6c6f5835 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/v-for.js +++ b/src/platforms/weex/compiler/modules/recycle-list/v-for.js @@ -3,7 +3,7 @@ import { forAliasRE, forIteratorRE } from 'compiler/parser/index' import { getAndRemoveAttr } from 'compiler/helpers' -export function transformVFor (el: ASTElement) { +export function transformVFor (el: ASTElement, options: CompilerOptions) { const exp = getAndRemoveAttr(el, 'v-for') if (!exp) { return @@ -27,5 +27,7 @@ export function transformVFor (el: ASTElement) { delete el.attrsMap['v-for'] el.attrsMap['[[repeat]]'] = desc el.attrsList.push({ name: '[[repeat]]', value: desc }) + } else if (process.env.NODE_ENV !== 'production' && options.warn) { + options.warn(`Invalid v-for expression: ${exp}`) } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-if.js b/src/platforms/weex/compiler/modules/recycle-list/v-if.js index 673fb09e7f2..f01010a251d 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/v-if.js +++ b/src/platforms/weex/compiler/modules/recycle-list/v-if.js @@ -2,12 +2,47 @@ import { getAndRemoveAttr } from 'compiler/helpers' -export function transformVIf (el: ASTElement) { - const exp = getAndRemoveAttr(el, 'v-if') - if (exp) { +function hasConditionDirective (el: ASTElement): boolean { + for (const attr in el.attrsMap) { + if (/^v\-if|v\-else|v\-else\-if$/.test(attr)) { + return true + } + } + return false +} + +function getPrevMatch (el: ASTElement): any { + if (el.parent && el.parent.children) { + const prev: Object = el.parent.children[el.parent.children.length - 1] + return prev.attrsMap['[[match]]'] + } +} + +export function transformVIf (el: ASTElement, options: CompilerOptions) { + if (hasConditionDirective(el)) { + let exp + const ifExp = getAndRemoveAttr(el, 'v-if') + const elseifExp = getAndRemoveAttr(el, 'v-else-if') + if (ifExp) { + exp = ifExp + } else { + const prevMatch = getPrevMatch(el) + if (prevMatch) { + exp = elseifExp + ? `!(${prevMatch}) && (${elseifExp})` // v-else-if + : `!(${prevMatch})` // v-else + } else if (process.env.NODE_ENV !== 'production' && options.warn) { + options.warn( + `v-${elseifExp ? ('else-if="' + elseifExp + '"') : 'else'} ` + + `used on element <${el.tag}> without corresponding v-if.` + ) + return + } + } el.attrsMap['[[match]]'] = exp el.attrsList.push({ name: '[[match]]', value: exp }) delete el.attrsMap['v-if'] + delete el.attrsMap['v-else-if'] + delete el.attrsMap['v-else'] } - // TODO: support v-else and v-else-if } From f42533c930d08f8b5dc4e608147266461a529d2f Mon Sep 17 00:00:00 2001 From: Hanks Date: Tue, 19 Sep 2017 18:29:26 +0800 Subject: [PATCH 6/6] feat($event): support binding parameters on event handler within weex recycle-list --- src/core/vdom/helpers/update-listeners.js | 16 +++++++++++----- src/platforms/weex/entry-framework.js | 4 ++-- src/platforms/weex/runtime/modules/events.js | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/core/vdom/helpers/update-listeners.js b/src/core/vdom/helpers/update-listeners.js index d587eecf38a..6b92f5da6de 100644 --- a/src/core/vdom/helpers/update-listeners.js +++ b/src/core/vdom/helpers/update-listeners.js @@ -1,13 +1,15 @@ /* @flow */ import { warn } from 'core/util/index' -import { cached, isUndef } from 'shared/util' +import { cached, isUndef, isPlainObject } from 'shared/util' const normalizeEvent = cached((name: string): { name: string, once: boolean, capture: boolean, - passive: boolean + passive: boolean, + handler?: Function, + params?: Array } => { const passive = name.charAt(0) === '&' name = passive ? name.slice(1) : name @@ -47,11 +49,15 @@ export function updateListeners ( remove: Function, vm: Component ) { - let name, cur, old, event + let name, def, cur, old, event for (name in on) { - cur = on[name] + def = cur = on[name] old = oldOn[name] event = normalizeEvent(name) + if (isPlainObject(def)) { + cur = def.handler + event.params = def.params + } if (isUndef(cur)) { process.env.NODE_ENV !== 'production' && warn( `Invalid handler for event "${event.name}": got ` + String(cur), @@ -61,7 +67,7 @@ export function updateListeners ( if (isUndef(cur.fns)) { cur = on[name] = createFnInvoker(cur) } - add(event.name, cur, event.once, event.capture, event.passive) + add(event.name, cur, event.once, event.capture, event.passive, event.params) } else if (cur !== old) { old.fns = cur on[name] = old diff --git a/src/platforms/weex/entry-framework.js b/src/platforms/weex/entry-framework.js index 303ad36b5f0..007b8aa1f79 100644 --- a/src/platforms/weex/entry-framework.js +++ b/src/platforms/weex/entry-framework.js @@ -162,10 +162,10 @@ const jsHandlers = { } } -function fireEvent (instance, nodeId, type, e, domChanges) { +function fireEvent (instance, nodeId, type, e, domChanges, params) { const el = instance.document.getRef(nodeId) if (el) { - return instance.document.fireEvent(el, type, e, domChanges) + return instance.document.fireEvent(el, type, e, domChanges, params) } return new Error(`invalid element reference "${nodeId}"`) } diff --git a/src/platforms/weex/runtime/modules/events.js b/src/platforms/weex/runtime/modules/events.js index 824f08e6154..bb642f60030 100755 --- a/src/platforms/weex/runtime/modules/events.js +++ b/src/platforms/weex/runtime/modules/events.js @@ -8,7 +8,9 @@ function add ( event: string, handler: Function, once: boolean, - capture: boolean + capture: boolean, + passive?: boolean, + params?: Array ) { if (capture) { console.log('Weex do not support event in bubble phase.') @@ -26,7 +28,7 @@ function add ( } } } - target.addEvent(event, handler) + target.addEvent(event, handler, params) } function remove (