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

Commit5c2ce00

Browse files
committed
feat(weex): WIP fix flow + handle errors in recycle-list template render
1 parent801f793 commit5c2ce00

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

‎flow/compiler.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ declare type CompilerOptions = {
2121
shouldDecodeNewlinesForHref?:boolean;
2222
optimize?:boolean;
2323

24-
// support <recycle-list> in weex
25-
recyclable?:boolean;
26-
2724
// for ssr optimization compiler
2825
scopeId?:string;
2926

@@ -37,7 +34,6 @@ declare type CompilerOptions = {
3734
declaretypeCompiledResult={
3835
ast: ?ASTElement;
3936
render:string;
40-
'@render'?:string;
4137
staticRenderFns:Array<string>;
4238
stringRenderFns?:Array<string>;
4339
errors?:Array<string>;

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ import {
1414
getTagNamespace
1515
}from'../util/index'
1616

17-
exportconstbaseOptions:CompilerOptions={
17+
exporttypeWeexCompilerOptions=CompilerOptions&{
18+
// whether to compile special template for <recycle-list>
19+
recyclable?:boolean;
20+
};
21+
22+
exporttypeWeexCompiledResult=CompiledResult&{
23+
'@render'?:string;
24+
};
25+
26+
exportconstbaseOptions:WeexCompilerOptions={
1827
modules,
1928
directives,
2029
isUnaryTag,
@@ -31,8 +40,8 @@ const compiler = createCompiler(baseOptions)
3140

3241
exportfunctioncompile(
3342
template:string,
34-
options?:CompilerOptions
35-
):CompiledResult{
43+
options?:WeexCompilerOptions
44+
):WeexCompiledResult{
3645
let generateAltRender=false
3746
if(options&&options.recyclable===true){
3847
generateAltRender=true

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import{addAttr}from'compiler/helpers'
44
import{RECYCLE_LIST_MARKER}from'weex/util/index'
5+
importtype{WeexCompilerOptions}from'weex/compiler/index'
56

67
// mark components as inside recycle-list so that we know we need to invoke
78
// their special@render function instead of render in create-component.js
8-
exportfunctionpostTransformComponent(el:ASTElement,options:CompilerOptions){
9+
exportfunctionpostTransformComponent(el:ASTElement,options:WeexCompilerOptions){
10+
// $flow-disable-line (we know isReservedTag is there)
911
if(!options.isReservedTag(el.tag)&&el.tag!=='cell-slot'){
1012
addAttr(el,RECYCLE_LIST_MARKER,true)
1113
}

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

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

3+
importtype{WeexCompilerOptions}from'weex/compiler/index'
34
import{postTransformComponent}from'./component'
45
import{postTransformText}from'./text'
56
import{preTransformVBind}from'./v-bind'
@@ -9,12 +10,12 @@ import { postTransformVOn } from './v-on'
910

1011
letcurrentRecycleList=null
1112

12-
functionshouldCompile(el:ASTElement,options:CompilerOptions){
13+
functionshouldCompile(el:ASTElement,options:WeexCompilerOptions){
1314
returnoptions.recyclable||
1415
(currentRecycleList&&el!==currentRecycleList)
1516
}
1617

17-
functionpreTransformNode(el:ASTElement,options:CompilerOptions){
18+
functionpreTransformNode(el:ASTElement,options:WeexCompilerOptions){
1819
if(el.tag==='recycle-list'){
1920
currentRecycleList=el
2021
}
@@ -25,13 +26,13 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
2526
}
2627
}
2728

28-
functiontransformNode(el:ASTElement,options:CompilerOptions){
29+
functiontransformNode(el:ASTElement,options:WeexCompilerOptions){
2930
if(shouldCompile(el,options)){
3031
// do nothing yet
3132
}
3233
}
3334

34-
functionpostTransformNode(el:ASTElement,options:CompilerOptions){
35+
functionpostTransformNode(el:ASTElement,options:WeexCompilerOptions){
3536
if(shouldCompile(el,options)){
3637
postTransformComponent(el,options)
3738
// <text>: transform children text into value attr
Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
/*@flow */
22

3+
import{warn}from'core/util/debug'
4+
import{handleError}from'core/util/error'
35
import{RECYCLE_LIST_MARKER}from'weex/util/index'
46
import{createComponentInstanceForVnode}from'core/vdom/create-component'
57

68
exportfunctionisRecyclableComponent(vnode:VNodeWithData):boolean{
7-
returnvnode.data.attrs&&(RECYCLE_LIST_MARKERinvnode.data.attrs)
9+
returnvnode.data.attrs
10+
?(RECYCLE_LIST_MARKERinvnode.data.attrs)
11+
:false
812
}
913

10-
exportfunctionrenderRecyclableComponentTemplate(vnode:VNodeWithData):VNode{
14+
exportfunctionrenderRecyclableComponentTemplate(vnode:MountedComponentVNode):VNode{
1115
// TODO:
12-
// 1. adding @isComponentRoot / @componentProps to the root node
13-
// 2. proper error handling
16+
// adding@isComponentRoot /@componentProps to the root node
17+
18+
// $flow-disable-line
1419
deletevnode.data.attrs[RECYCLE_LIST_MARKER]
15-
constinstance=createComponentInstanceForVnode(vnode)
16-
returninstance.$options['@render'].call(instance)
20+
constvm=createComponentInstanceForVnode(vnode)
21+
constrender=(vm.$options:any)['@render']
22+
if(render){
23+
try{
24+
returnrender.call(vm)
25+
}catch(err){
26+
handleError(err,vm,`@render`)
27+
}
28+
}else{
29+
warn(
30+
`@render function not defined on component used in <recycle-list>. `+
31+
`Make sure to declare \`recyclable="true"\` on the component's template.`,
32+
vm
33+
)
34+
}
1735
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp