Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/platforms/weex/compiler/modules/append.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/* @flow */

import { makeMap } from 'shared/util'

// The "unitary tag" means that the tag node and its children
// must be sent to the native together.
const isUnitaryTag = makeMap('cell,header,cell-slot,recycle-list', true)

function preTransformNode (el: ASTElement, options: CompilerOptions) {
if (el.tag === 'cell' && !el.attrsList.some(item => item.name === 'append')) {
if (isUnitaryTag(el.tag) && !el.attrsList.some(item => item.name === 'append')) {
el.attrsMap.append = 'tree'
el.attrsList.push({ name: 'append', value: 'tree' })
}
Expand Down
2 changes: 1 addition & 1 deletion test/weex/cases/cases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('Usage', () => {
}]).then(code => {
const id = String(Date.now() * Math.random())
const instance = createInstance(id, code)
expect(tasks.length).toEqual(7)
expect(tasks.length).toEqual(3)
tasks.length = 0
instance.$triggerHook(2, 'create', ['component-1'])
instance.$triggerHook(2, 'create', ['component-2'])
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/attrs.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A', count: 1, source: 'http://whatever.com/x.png' },
{ type: 'A', count: 2, source: 'http://whatever.com/y.png' },
Expand All @@ -11,7 +12,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'image',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/classname.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A', color: 'red' },
{ type: 'A', color: 'blue' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
style: {
backgroundColor: '#FF6600'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'div',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/components/stateful.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A', number: 24 },
{ type: 'A', number: 42 }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'div',
attr: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'B', poster: 'yy', title: 'y' },
Expand All @@ -11,7 +12,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'div',
attr: {
Expand Down Expand Up @@ -51,7 +52,7 @@
}]
}, {
type: 'cell-slot',
attr: { templateType: 'B' },
attr: { append: 'tree', templateType: 'B' },
children: [{
type: 'div',
attr: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A', poster: 'xx', title: 'x' },
{ type: 'A', poster: 'yy', title: 'y' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'div',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/components/stateless.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'div',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/inline-style.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A', color: '#606060' },
{ type: 'A', color: '#E5E5E5' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
style: {
backgroundColor: '#FF6600'
},
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/text-node.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A', dynamic: 'decimal', two: '2', four: '4' },
{ type: 'A', dynamic: 'binary', two: '10', four: '100' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'text',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/v-else-if.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'image',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/v-else.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'image',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/v-for-iterator.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'div',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/v-for.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'div',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/v-if.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'image',
attr: {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/v-on-inline.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'text',
event: ['click', {
Expand Down
3 changes: 2 additions & 1 deletion test/weex/cases/recycle-list/v-on.vdom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
({
type: 'recycle-list',
attr: {
append: 'tree',
listData: [
{ type: 'A' },
{ type: 'A' }
Expand All @@ -10,7 +11,7 @@
},
children: [{
type: 'cell-slot',
attr: { templateType: 'A' },
attr: { append: 'tree', templateType: 'A' },
children: [{
type: 'text',
event: ['click', 'longpress'],
Expand Down
35 changes: 34 additions & 1 deletion test/weex/compiler/append.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { compile } from '../../../packages/weex-template-compiler'
import { strToRegExp } from '../helpers/index'

describe('append props', () => {
it('append="tree"', () => {
it('add append="tree" on <cell>', () => {
const { render, staticRenderFns, errors } = compile(`<list><cell></cell></list>`)
expect(render).not.toBeUndefined()
expect(staticRenderFns).not.toBeUndefined()
Expand All @@ -11,4 +11,37 @@ describe('append props', () => {
expect(staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
expect(errors).toEqual([])
})

it('override append="node" on <cell>', () => {
const { render, staticRenderFns, errors } = compile(`<list><cell append="node"></cell></list>`)
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"node"}`))
expect(errors).toEqual([])
})

it('add append="tree" on <header>', () => {
const { render, staticRenderFns, errors } = compile(`<list><header></header></list>`)
expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
expect(errors).toEqual([])
})

it('add append="tree" on <recycle-list>', () => {
const { render, staticRenderFns, errors } = compile(`<recycle-list><div></div></recycle-list>`)
expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
expect(errors).toEqual([])
})

it('add append="tree" on <cell-slot>', () => {
const { render, staticRenderFns, errors } = compile(`<list><cell-slot></cell-slot></list>`)
expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
expect(errors).toEqual([])
})

it('override append="node" on <cell-slot>', () => {
const { render, staticRenderFns, errors } = compile(`<list><cell-slot append="node"></cell-slot></list>`)
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"node"}`))
expect(errors).toEqual([])
})
})