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

Commit88f3889

Browse files
committed
feat(weex): WIP mark recycle list child component root
1 parentb06d09f commit88f3889

File tree

9 files changed

+43
-19
lines changed

9 files changed

+43
-19
lines changed

‎src/compiler/helpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export function addAttr (el: ASTElement, name: string, value: any) {
2626
el.plain=false
2727
}
2828

29+
// add a raw attr (use this in preTransforms)
30+
exportfunctionaddRawAttr(el:ASTElement,name:string,value:any){
31+
el.attrsMap[name]=value
32+
el.attrsList.push({ name, value})
33+
}
34+
2935
exportfunctionaddDirective(
3036
el:ASTElement,
3137
name:string,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import VNode from './vnode'
44
import{resolveConstructorOptions}from'core/instance/init'
55
import{queueActivatedComponent}from'core/observer/scheduler'
66
import{createFunctionalComponent}from'./create-functional-component'
7-
import{renderRecyclableComponentTemplate}from'weex/runtime/recycle-list/render-component-template'
87

98
import{
109
warn,
@@ -28,6 +27,11 @@ import {
2827
deactivateChildComponent
2928
}from'../instance/lifecycle'
3029

30+
import{
31+
isRecyclableComponent,
32+
renderRecyclableComponentTemplate
33+
}from'weex/runtime/recycle-list/render-component-template'
34+
3135
// hooks to be invoked on component VNodes during patch
3236
constcomponentVNodeHooks={
3337
init(
@@ -196,7 +200,7 @@ export function createComponent (
196200
// Weex specific: invoke recycle-list optimized @render function for
197201
// extracting cell-slot template.
198202
// https://github.com/Hanks10100/weex-native-directive/tree/master/component
199-
if(__WEEX__&&data.attrs&&('@inRecycleList'indata.attrs)){
203+
if(__WEEX__&&isRecyclableComponent(vnode)){
200204
returnrenderRecyclableComponentTemplate(vnode)
201205
}
202206

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*@flow */
2+
3+
import{addRawAttr}from'compiler/helpers'
4+
5+
// mark component root nodes as
6+
exportfunctionpreTransformComponentRoot(
7+
el:ASTElement,
8+
options:WeexCompilerOptions
9+
){
10+
if(!el.parent){
11+
// component root
12+
addRawAttr(el,'$isComponentRoot',true)
13+
}
14+
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
/*@flow */
22

3-
import{addAttr}from'compiler/helpers'
3+
import{addRawAttr}from'compiler/helpers'
44
import{RECYCLE_LIST_MARKER}from'weex/util/index'
55

66
// mark components as inside recycle-list so that we know we need to invoke
77
// their special@render function instead of render in create-component.js
8-
exportfunctionpostTransformComponent(el:ASTElement,options:WeexCompilerOptions){
8+
exportfunctionpreTransformComponent(
9+
el:ASTElement,
10+
options:WeexCompilerOptions
11+
){
912
// $flow-disable-line (we know isReservedTag is there)
1013
if(!options.isReservedTag(el.tag)&&el.tag!=='cell-slot'){
11-
addAttr(el,RECYCLE_LIST_MARKER,true)
14+
addRawAttr(el,RECYCLE_LIST_MARKER,'true')
1215
}
1316
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*@flow */
22

3-
import{postTransformComponent}from'./component'
3+
import{preTransformComponent}from'./component'
4+
import{preTransformComponentRoot}from'./component-root'
45
import{postTransformText}from'./text'
56
import{preTransformVBind}from'./v-bind'
67
import{preTransformVIf}from'./v-if'
@@ -19,6 +20,8 @@ function preTransformNode (el: ASTElement, options: WeexCompilerOptions) {
1920
currentRecycleList=el
2021
}
2122
if(shouldCompile(el,options)){
23+
preTransformComponent(el,options)
24+
preTransformComponentRoot(el,options)
2225
preTransformVBind(el,options)
2326
preTransformVIf(el,options)// also v-else-if and v-else
2427
preTransformVFor(el,options)
@@ -33,7 +36,6 @@ function transformNode (el: ASTElement, options: WeexCompilerOptions) {
3336

3437
functionpostTransformNode(el:ASTElement,options:WeexCompilerOptions){
3538
if(shouldCompile(el,options)){
36-
postTransformComponent(el,options)
3739
// <text>: transform children text into value attr
3840
if(el.tag==='text'){
3941
postTransformText(el,options)

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import{camelize}from'shared/util'
44
import{bindRE}from'compiler/parser/index'
5-
import{getAndRemoveAttr}from'compiler/helpers'
5+
import{getAndRemoveAttr,addRawAttr}from'compiler/helpers'
66

77
functionparseAttrName(name:string):string{
88
returncamelize(name.replace(bindRE,''))
@@ -16,10 +16,7 @@ export function preTransformVBind (el: ASTElement, options: WeexCompilerOptions)
1616
'@binding':getAndRemoveAttr(el,attr)
1717
}
1818
deleteel.attrsMap[attr]
19-
el.attrsMap[name]=value
20-
el.attrsList.push({ name, value})
21-
// addAttr(el, name, value)
22-
// el.hasBindings = false
19+
addRawAttr(el,name,value)
2320
}
2421
}
2522
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*@flow */
22

33
import{forAliasRE,forIteratorRE,stripParensRE}from'compiler/parser/index'
4-
import{getAndRemoveAttr}from'compiler/helpers'
4+
import{getAndRemoveAttr,addRawAttr}from'compiler/helpers'
55

66
exportfunctionpreTransformVFor(el:ASTElement,options:WeexCompilerOptions){
77
constexp=getAndRemoveAttr(el,'v-for')
@@ -26,8 +26,7 @@ export function preTransformVFor (el: ASTElement, options: WeexCompilerOptions)
2626
}
2727
}
2828
deleteel.attrsMap['v-for']
29-
el.attrsMap['[[repeat]]']=desc
30-
el.attrsList.push({name:'[[repeat]]',value:desc})
29+
addRawAttr(el,'[[repeat]]',desc)
3130
}elseif(process.env.NODE_ENV!=='production'&&options.warn){
3231
options.warn(`Invalid v-for expression:${exp}`)
3332
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*@flow */
22

3-
import{getAndRemoveAttr}from'compiler/helpers'
3+
import{getAndRemoveAttr,addRawAttr}from'compiler/helpers'
44

55
functionhasConditionDirective(el:ASTElement):boolean{
66
for(constattrinel.attrsMap){
@@ -42,7 +42,6 @@ export function preTransformVIf (el: ASTElement, options: WeexCompilerOptions) {
4242
return
4343
}
4444
}
45-
el.attrsMap['[[match]]']=exp
46-
el.attrsList.push({name:'[[match]]',value:exp})
45+
addRawAttr(el,'[[match]]',exp)
4746
}
4847
}

‎src/platforms/weex/util/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare var document: Object;
44
import{makeMap}from'shared/util'
55
import{warn}from'core/util/index'
66

7-
exportconstRECYCLE_LIST_MARKER='@inRecycleList'
7+
exportconstRECYCLE_LIST_MARKER='$inRecycleList'
88

99
exportconstisReservedTag=makeMap(
1010
'template,script,style,element,content,slot,link,meta,svg,view,'+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp