Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [jsfm] support append tree on root element
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanks10100 committed Dec 22, 2017
1 parent a45d51b commit 9afc4d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
10 changes: 2 additions & 8 deletions html5/runtime/vdom/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,9 @@ export function appendBody (doc, node, before) {

function sendBody (doc, node) {
const body = node.toJSON()
const children = body.children
delete body.children
let result = doc.taskCenter.send('dom', { action: 'createBody' }, [body])
if (children) {
children.forEach(child => {
result = doc.taskCenter.send('dom', { action: 'addElement' }, [body.ref, child, -1])
})
if (doc && doc.taskCenter && typeof doc.taskCenter.send === 'function') {
doc.taskCenter.send('dom', { action: 'createBody' }, [body])
}
return result
}

/**
Expand Down
20 changes: 8 additions & 12 deletions html5/test/unit/default/vm/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,16 @@ describe('generate virtual dom for a single vm', () => {
attr: {
append: 'tree'
},
children: [{
ref: spy.firstCall.args[2].children[0].ref,
type: 'text',
attr: {
value: '<some text content>'
},
style: {}
}],
style: {}
})
expect(spy.secondCall.args[0]).to.be.equal('test')
expect(spy.secondCall.args[1]).to.be.equal('addElement')
expect(spy.secondCall.args[2]).to.be.equal('_root')
expect(spy.secondCall.args[3]).to.deep.equal({
ref: spy.secondCall.args[3].ref,
type: 'text',
attr: {
value: '<some text content>'
},
style: {}
})
expect(spy.secondCall.args[4]).to.be.equal(-1)

expect(vm._app).equal(app)
const el = doc.body
Expand Down

0 comments on commit 9afc4d5

Please sign in to comment.