Skip to content

Commit

Permalink
feat($compiler): supports compiling v-for to the weex native directive
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanks10100 authored and yyx990803 committed Dec 19, 2017
1 parent 7ad368e commit 9bd1483
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/platforms/weex/compiler/modules/recycle-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -16,6 +17,7 @@ function transformNode (el: ASTElement) {
if (currentRecycleList) {
// TODO
transformVIf(el)
transformVFor(el)
transformVBind(el)
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/platforms/weex/compiler/modules/recycle-list/v-for.js
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 9bd1483

Please sign in to comment.