Skip to content

Commit

Permalink
feat(weex): recycle-list support stateful child component
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 19, 2017
1 parent 452a65c commit 70b97ac
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
6 changes: 5 additions & 1 deletion src/core/util/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export function validateProp (
observe(value)
observerState.shouldConvert = prevShouldConvert
}
if (process.env.NODE_ENV !== 'production') {
if (
process.env.NODE_ENV !== 'production' &&
// skip validation for weex recycle-list child component props
!(__WEEX__ && isObject(value) && ('@binding' in value))
) {
assertProp(prop, key, value, vm, absent)
}
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export function postTransformComponentRoot (
if (!el.parent) {
// component root
addAttr(el, '@isComponentRoot', 'true')
addAttr(el, '@componentProps', JSON.stringify({}))
addAttr(el, '@componentProps', '$props || {}')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export function isRecyclableComponent (vnode: VNodeWithData): boolean {
}

export function renderRecyclableComponentTemplate (vnode: MountedComponentVNode): VNode {
// TODO:
// adding @isComponentRoot / @componentProps to the root node

// $flow-disable-line
delete vnode.data.attrs[RECYCLE_LIST_MARKER]
const vm = createComponentInstanceForVnode(vnode)
Expand Down
68 changes: 33 additions & 35 deletions test/weex/cases/cases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,41 +84,39 @@ describe('Usage', () => {
}).catch(done.fail)
})

// it('stateless component with props', done => {
// compileWithDeps('recycle-list/components/stateless-with-props.vue', [{
// name: 'poster',
// path: 'recycle-list/components/poster.vue'
// }]).then(code => {
// const id = String(Date.now() * Math.random())
// const instance = createInstance(id, code)
// setTimeout(() => {
// const target = readObject('recycle-list/components/stateless-with-props.vdom.js')
// expect(getRoot(instance)).toEqual(target)
// done()
// }, 50)
// }).catch(done.fail)
// })
it('stateless component with props', done => {
compileWithDeps('recycle-list/components/stateless-with-props.vue', [{
name: 'poster',
path: 'recycle-list/components/poster.vue'
}]).then(code => {
const id = String(Date.now() * Math.random())
const instance = createInstance(id, code)
setTimeout(() => {
const target = readObject('recycle-list/components/stateless-with-props.vdom.js')
expect(getRoot(instance)).toEqual(target)
done()
}, 50)
}).catch(done.fail)
})

// it('stateful component', done => {
// compileWithDeps('recycle-list/components/stateful.vue', [{
// name: 'counter',
// path: 'recycle-list/components/counter.vue'
// }]).then(code => {
// const id = String(Date.now() * Math.random())
// const instance = createInstance(id, code)
// setTimeout(() => {
// const target = readObject('recycle-list/components/stateful.vdom.js')
// expect(getRoot(instance)).toEqual(target)
// const event = getEvents(instance)[0]
// fireEvent(instance, event.ref, event.type, {})
// setTimeout(() => {
// // TODO: check render results
// // expect(getRoot(instance)).toEqual(target)
// done()
// })
// }, 50)
// }).catch(done.fail)
// })
it('stateful component', done => {
compileWithDeps('recycle-list/components/stateful.vue', [{
name: 'counter',
path: 'recycle-list/components/counter.vue'
}]).then(code => {
const id = String(Date.now() * Math.random())
const instance = createInstance(id, code)
setTimeout(() => {
const target = readObject('recycle-list/components/stateful.vdom.js')
expect(getRoot(instance)).toEqual(target)
const event = getEvents(instance)[0]
fireEvent(instance, event.ref, event.type, {})
setTimeout(() => {
expect(getRoot(instance)).toEqual(target)
done()
})
}, 50)
}).catch(done.fail)
})
})
})

2 changes: 1 addition & 1 deletion test/weex/cases/recycle-list/components/poster.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template>
<template recyclable="true">
<div>
<image class="image" :src="imageUrl"></image>
<text class="title">{{title}}</text>
Expand Down

0 comments on commit 70b97ac

Please sign in to comment.