Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commit2cb8ea3

Browse files
Hanks10100yyx990803
authored andcommitted
feat(weex): support compilingv-on in the weex native directive (vuejs#6892)
* refactor(compiler): move postTransforms to after children are processed* feat(weex): recycle-list support WIP* refactor: fix types* feat(weex): split text into separate module* feat($compiler): supports compiling v-bind to the weex native directive in recycle-list* feat(compile): supports compiling v-if to the weex native directive* feat($compiler): supports compiling v-for to the weex native directive* feat($compiler): compile weex native directives in preTransformNode* feat($compiler): supports compiling v-else-if and v-else to the weex native directive* feat($event): support binding parameters on event handler within weex recycle-list* refactor: mark weex-specific block* feat(wip): recycle list template inline expand* build: add weex factory dev script* feat($compiler): support to compile "v-on" into weex native directive* feat($compiler): adjust handler params to fit the weex native renderer+ Filter the non-expression params and the `$event`.+ Use `$event` as the last argument of handler.
1 parentac99957 commit2cb8ea3

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

‎flow/compiler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ declare type ASTIfConditions = Array<ASTIfCondition>;
5656

5757
declaretypeASTElementHandler={
5858
value:string;
59+
params?:Array<any>;
5960
modifiers: ?ASTModifiers;
6061
};
6162

‎src/compiler/codegen/events.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ export function genHandlers (
4646
return res.slice(0, -1) + '}'
4747
}
4848
49+
// Generate handler code with binding params on Weex
50+
function genWeexHandler (params: Array<any>, handlerCode: string) {
51+
const wrapperArgs = params.filter(exp => simplePathRE.test(exp) && exp !== '$event')
52+
const handlerParams = wrapperArgs.map(exp => ({ '@binding': exp }))
53+
wrapperArgs.push('$event')
54+
return '{' +
55+
`handler:function(${wrapperArgs.join(',')}){${handlerCode}},\n`+
56+
`params:${JSON.stringify(handlerParams)}`+
57+
'}'
58+
}
59+
4960
functiongenHandler(
5061
name:string,
5162
handler:ASTElementHandler|Array<ASTElementHandler>
@@ -62,9 +73,14 @@ function genHandler (
6273
constisFunctionExpression=fnExpRE.test(handler.value)
6374

6475
if(!handler.modifiers){
65-
return isMethodPath || isFunctionExpression
66-
? handler.value
67-
: `function($event){${handler.value}}` // inline statement
76+
if(isMethodPath||isFunctionExpression){
77+
returnhandler.value
78+
}
79+
// $flow-disable-line
80+
if(__WEEX__&&handler.params){
81+
returngenWeexHandler(handler.params,handler.value)
82+
}
83+
return`function($event){${handler.value}}`// inline statement
6884
}else{
6985
let code=''
7086
letgenModifierCode=''
@@ -100,6 +116,10 @@ function genHandler (
100116
:isFunctionExpression
101117
? `(${handler.value})($event)`
102118
: handler.value
119+
// $flow-disable-line
120+
if (__WEEX__ && handler.params) {
121+
return genWeexHandler(handler.params, code + handlerCode)
122+
}
103123
return `function($event){${code}${handlerCode}}`
104124
}
105125
}

‎src/core/vdom/create-component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ export function createComponent (
145145
data=data||{}
146146

147147
// recycle-list optimized render function for extracting cell-slot
148-
// template. This isessentailly inline expanding instead of creating
148+
// template. This isessentially inline expanding instead of creating
149149
// an actual instance.
150150
// https://github.com/Hanks10100/weex-native-directive/tree/master/component
151151
// $flow-disable-line
152-
if(__WEEX__&&data.attrs['@isInRecycleList']){
152+
if(__WEEX__&&data.attrs&&data.attrs['@isInRecycleList']){
153153
const altRender=Ctor.options['@render']
154154
if(altRender){
155155
returnaltRender.call(

‎src/platforms/weex/compiler/modules/recycle-list/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { transformText } from './text'
44
import{transformVBind}from'./v-bind'
55
import{transformVIf}from'./v-if'
66
import{transformVFor}from'./v-for'
7+
import{postTransformVOn}from'./v-on'
78

89
letcurrentRecycleList=null
910

@@ -31,6 +32,7 @@ function postTransformNode (el: ASTElement) {
3132
if(el.tag==='text'){
3233
transformText(el)
3334
}
35+
postTransformVOn(el)
3436
}
3537
if(el===currentRecycleList){
3638
currentRecycleList=null
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*@flow */
2+
3+
constinlineStatementRE=/^\s*([A-Za-z_$0-9\.]+)*\s*\(\s*(([A-Za-z_$0-9\'\"]+)?(\s*,\s*([A-Za-z_$0-9\'\"]+))*)\s*\)$/
4+
5+
functionparseHandlerParams(handler:ASTElementHandler){
6+
constres=inlineStatementRE.exec(handler.value)
7+
if(res&&res[2]){
8+
handler.params=res[2].split(/\s*,\s*/)
9+
}
10+
}
11+
12+
exportfunctionpostTransformVOn(el:ASTElement){
13+
constevents:ASTElementHandlers|void=el.events
14+
if(!events){
15+
return
16+
}
17+
for(constnameinevents){
18+
consthandler:ASTElementHandler|Array<ASTElementHandler> = events[name]
19+
if (Array.isArray(handler)){
20+
handler.map(fn=>parseHandlerParams(fn))
21+
} else{
22+
parseHandlerParams(handler)
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp