Skip to content

Commit 48f6400

Browse files
Hanks10100hefeng
authored and
hefeng
committed
fix(weex): append as tree by default for recycle-list and cell-slot (vuejs#7216)
1 parent 2014a95 commit 48f6400

19 files changed

+75
-20
lines changed

src/platforms/weex/compiler/modules/append.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/* @flow */
22

3+
import { makeMap } from 'shared/util'
4+
5+
// The "unitary tag" means that the tag node and its children
6+
// must be sent to the native together.
7+
const isUnitaryTag = makeMap('cell,header,cell-slot,recycle-list', true)
8+
39
function preTransformNode (el: ASTElement, options: CompilerOptions) {
4-
if (el.tag === 'cell' && !el.attrsList.some(item => item.name === 'append')) {
10+
if (isUnitaryTag(el.tag) && !el.attrsList.some(item => item.name === 'append')) {
511
el.attrsMap.append = 'tree'
612
el.attrsList.push({ name: 'append', value: 'tree' })
713
}

test/weex/cases/cases.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('Usage', () => {
136136
}]).then(code => {
137137
const id = String(Date.now() * Math.random())
138138
const instance = createInstance(id, code)
139-
expect(tasks.length).toEqual(7)
139+
expect(tasks.length).toEqual(3)
140140
tasks.length = 0
141141
instance.$triggerHook(2, 'create', ['component-1'])
142142
instance.$triggerHook(2, 'create', ['component-2'])

test/weex/cases/recycle-list/attrs.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A', count: 1, source: 'http://whatever.com/x.png' },
67
{ type: 'A', count: 2, source: 'http://whatever.com/y.png' },
@@ -11,7 +12,7 @@
1112
},
1213
children: [{
1314
type: 'cell-slot',
14-
attr: { templateType: 'A' },
15+
attr: { append: 'tree', templateType: 'A' },
1516
children: [{
1617
type: 'image',
1718
attr: {

test/weex/cases/recycle-list/classname.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A', color: 'red' },
67
{ type: 'A', color: 'blue' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
style: {
1516
backgroundColor: '#FF6600'
1617
},

test/weex/cases/recycle-list/components/stateful-v-model.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'div',
1617
attr: {

test/weex/cases/recycle-list/components/stateful.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A', number: 24 },
67
{ type: 'A', number: 42 }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'div',
1617
attr: {

test/weex/cases/recycle-list/components/stateless-multi-components.vdom.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'B', poster: 'yy', title: 'y' },
@@ -11,7 +12,7 @@
1112
},
1213
children: [{
1314
type: 'cell-slot',
14-
attr: { templateType: 'A' },
15+
attr: { append: 'tree', templateType: 'A' },
1516
children: [{
1617
type: 'div',
1718
attr: {
@@ -51,7 +52,7 @@
5152
}]
5253
}, {
5354
type: 'cell-slot',
54-
attr: { templateType: 'B' },
55+
attr: { append: 'tree', templateType: 'B' },
5556
children: [{
5657
type: 'div',
5758
attr: {

test/weex/cases/recycle-list/components/stateless-with-props.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A', poster: 'xx', title: 'x' },
67
{ type: 'A', poster: 'yy', title: 'y' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'div',
1617
attr: {

test/weex/cases/recycle-list/components/stateless.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'div',
1617
attr: {

test/weex/cases/recycle-list/inline-style.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A', color: '#606060' },
67
{ type: 'A', color: '#E5E5E5' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
style: {
1516
backgroundColor: '#FF6600'
1617
},

test/weex/cases/recycle-list/text-node.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A', dynamic: 'decimal', two: '2', four: '4' },
67
{ type: 'A', dynamic: 'binary', two: '10', four: '100' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'text',
1617
attr: {

test/weex/cases/recycle-list/v-else-if.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'image',
1617
attr: {

test/weex/cases/recycle-list/v-else.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'image',
1617
attr: {

test/weex/cases/recycle-list/v-for-iterator.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'div',
1617
attr: {

test/weex/cases/recycle-list/v-for.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'div',
1617
attr: {

test/weex/cases/recycle-list/v-if.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'image',
1617
attr: {

test/weex/cases/recycle-list/v-on-inline.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'text',
1617
event: ['click', {

test/weex/cases/recycle-list/v-on.vdom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
({
22
type: 'recycle-list',
33
attr: {
4+
append: 'tree',
45
listData: [
56
{ type: 'A' },
67
{ type: 'A' }
@@ -10,7 +11,7 @@
1011
},
1112
children: [{
1213
type: 'cell-slot',
13-
attr: { templateType: 'A' },
14+
attr: { append: 'tree', templateType: 'A' },
1415
children: [{
1516
type: 'text',
1617
event: ['click', 'longpress'],

test/weex/compiler/append.spec.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { compile } from '../../../packages/weex-template-compiler'
22
import { strToRegExp } from '../helpers/index'
33

44
describe('append props', () => {
5-
it('append="tree"', () => {
5+
it('add append="tree" on <cell>', () => {
66
const { render, staticRenderFns, errors } = compile(`<list><cell></cell></list>`)
77
expect(render).not.toBeUndefined()
88
expect(staticRenderFns).not.toBeUndefined()
@@ -11,4 +11,37 @@ describe('append props', () => {
1111
expect(staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
1212
expect(errors).toEqual([])
1313
})
14+
15+
it('override append="node" on <cell>', () => {
16+
const { render, staticRenderFns, errors } = compile(`<list><cell append="node"></cell></list>`)
17+
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"node"}`))
18+
expect(errors).toEqual([])
19+
})
20+
21+
it('add append="tree" on <header>', () => {
22+
const { render, staticRenderFns, errors } = compile(`<list><header></header></list>`)
23+
expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
24+
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
25+
expect(errors).toEqual([])
26+
})
27+
28+
it('add append="tree" on <recycle-list>', () => {
29+
const { render, staticRenderFns, errors } = compile(`<recycle-list><div></div></recycle-list>`)
30+
expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
31+
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
32+
expect(errors).toEqual([])
33+
})
34+
35+
it('add append="tree" on <cell-slot>', () => {
36+
const { render, staticRenderFns, errors } = compile(`<list><cell-slot></cell-slot></list>`)
37+
expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`))
38+
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`))
39+
expect(errors).toEqual([])
40+
})
41+
42+
it('override append="node" on <cell-slot>', () => {
43+
const { render, staticRenderFns, errors } = compile(`<list><cell-slot append="node"></cell-slot></list>`)
44+
expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"node"}`))
45+
expect(errors).toEqual([])
46+
})
1447
})

0 commit comments

Comments
 (0)