Skip to content

Commit 70b97ac

Browse files
committed
feat(weex): recycle-list support stateful child component
1 parent 452a65c commit 70b97ac

File tree

5 files changed

+40
-41
lines changed

5 files changed

+40
-41
lines changed

src/core/util/props.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ export function validateProp (
4545
observe(value)
4646
observerState.shouldConvert = prevShouldConvert
4747
}
48-
if (process.env.NODE_ENV !== 'production') {
48+
if (
49+
process.env.NODE_ENV !== 'production' &&
50+
// skip validation for weex recycle-list child component props
51+
!(__WEEX__ && isObject(value) && ('@binding' in value))
52+
) {
4953
assertProp(prop, key, value, vm, absent)
5054
}
5155
return value

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export function postTransformComponentRoot (
1010
if (!el.parent) {
1111
// component root
1212
addAttr(el, '@isComponentRoot', 'true')
13-
addAttr(el, '@componentProps', JSON.stringify({}))
13+
addAttr(el, '@componentProps', '$props || {}')
1414
}
1515
}

src/platforms/weex/runtime/recycle-list/render-component-template.js

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ export function isRecyclableComponent (vnode: VNodeWithData): boolean {
1212
}
1313

1414
export function renderRecyclableComponentTemplate (vnode: MountedComponentVNode): VNode {
15-
// TODO:
16-
// adding @isComponentRoot / @componentProps to the root node
17-
1815
// $flow-disable-line
1916
delete vnode.data.attrs[RECYCLE_LIST_MARKER]
2017
const vm = createComponentInstanceForVnode(vnode)

test/weex/cases/cases.spec.js

+33-35
Original file line numberDiff line numberDiff line change
@@ -84,41 +84,39 @@ describe('Usage', () => {
8484
}).catch(done.fail)
8585
})
8686

87-
// it('stateless component with props', done => {
88-
// compileWithDeps('recycle-list/components/stateless-with-props.vue', [{
89-
// name: 'poster',
90-
// path: 'recycle-list/components/poster.vue'
91-
// }]).then(code => {
92-
// const id = String(Date.now() * Math.random())
93-
// const instance = createInstance(id, code)
94-
// setTimeout(() => {
95-
// const target = readObject('recycle-list/components/stateless-with-props.vdom.js')
96-
// expect(getRoot(instance)).toEqual(target)
97-
// done()
98-
// }, 50)
99-
// }).catch(done.fail)
100-
// })
87+
it('stateless component with props', done => {
88+
compileWithDeps('recycle-list/components/stateless-with-props.vue', [{
89+
name: 'poster',
90+
path: 'recycle-list/components/poster.vue'
91+
}]).then(code => {
92+
const id = String(Date.now() * Math.random())
93+
const instance = createInstance(id, code)
94+
setTimeout(() => {
95+
const target = readObject('recycle-list/components/stateless-with-props.vdom.js')
96+
expect(getRoot(instance)).toEqual(target)
97+
done()
98+
}, 50)
99+
}).catch(done.fail)
100+
})
101101

102-
// it('stateful component', done => {
103-
// compileWithDeps('recycle-list/components/stateful.vue', [{
104-
// name: 'counter',
105-
// path: 'recycle-list/components/counter.vue'
106-
// }]).then(code => {
107-
// const id = String(Date.now() * Math.random())
108-
// const instance = createInstance(id, code)
109-
// setTimeout(() => {
110-
// const target = readObject('recycle-list/components/stateful.vdom.js')
111-
// expect(getRoot(instance)).toEqual(target)
112-
// const event = getEvents(instance)[0]
113-
// fireEvent(instance, event.ref, event.type, {})
114-
// setTimeout(() => {
115-
// // TODO: check render results
116-
// // expect(getRoot(instance)).toEqual(target)
117-
// done()
118-
// })
119-
// }, 50)
120-
// }).catch(done.fail)
121-
// })
102+
it('stateful component', done => {
103+
compileWithDeps('recycle-list/components/stateful.vue', [{
104+
name: 'counter',
105+
path: 'recycle-list/components/counter.vue'
106+
}]).then(code => {
107+
const id = String(Date.now() * Math.random())
108+
const instance = createInstance(id, code)
109+
setTimeout(() => {
110+
const target = readObject('recycle-list/components/stateful.vdom.js')
111+
expect(getRoot(instance)).toEqual(target)
112+
const event = getEvents(instance)[0]
113+
fireEvent(instance, event.ref, event.type, {})
114+
setTimeout(() => {
115+
expect(getRoot(instance)).toEqual(target)
116+
done()
117+
})
118+
}, 50)
119+
}).catch(done.fail)
120+
})
122121
})
123122
})
124-

test/weex/cases/recycle-list/components/poster.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<template>
1+
<template recyclable="true">
22
<div>
33
<image class="image" :src="imageUrl"></image>
44
<text class="title">{{title}}</text>

0 commit comments

Comments
 (0)