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
2 changes: 2 additions & 0 deletions __tests__/renderer/ViewNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ describe('ViewNode', () => {
expect(prevChildNode.nextSibling).toEqual(nextChildNode)
expect(nextChildNode.prevSibling).toEqual(prevChildNode)
expect(childNode.parentNode).toBeNull()
expect(childNode.prevSibling).toBeNull()
expect(childNode.nextSibling).toBeNull()
})

test('nativeView can be set once', () => {
Expand Down
6 changes: 6 additions & 0 deletions platform/nativescript/renderer/ViewNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ export default class ViewNode {
childNode.nextSibling.prevSibling = childNode.prevSibling
}

// reset the prevSibling and nextSibling. If not, a keep-alived component will
// still have a filled nextSibling attribute so vue will not
// insert the node again to the parent. See #220
childNode.prevSibling = null
childNode.nextSibling = null

this.childNodes = this.childNodes.filter(node => node !== childNode)

viewUtil.removeChild(this, childNode)
Expand Down
6 changes: 3 additions & 3 deletions platform/nativescript/runtime/node-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ export function appendChild(node, child) {
}

export function parentNode(node) {
trace(`ParentNode(${node})`)
trace(`ParentNode(${node}) -> ${node.parentNode}`)

return node.parentNode
}

export function nextSibling(node) {
trace(`NextSibling(${node})`)
trace(`NextSibling(${node}) -> ${node.nextSibling}`)

return node.nextSibling
}

export function tagName(elementNode) {
trace(`TagName(${elementNode})`)
trace(`TagName(${elementNode}) -> ${elementNode.tagName}`)

return elementNode.tagName
}
Expand Down
14 changes: 6 additions & 8 deletions samples/app/220.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ Vue.config.silent = false

const CompButton = {
template: `
<Button @tap="counter++">{{label}}: {{counter}}</Button>
<Button>{{label}}: {{counter}}</Button>
`,
name: 'CompButton',
props: ['label'],
data() {
return {
counter: 0
}
props: ['label', 'counter'],
destroyed() {
console.log('Component destroyed. This should not happen')
}
}

Expand All @@ -27,8 +25,8 @@ new Vue({
<StackLayout>
<Button @tap="counter++">{{counter}}</Button>
<keep-alive>
<CompButton v-if="counter % 2" key="odd" label="Odd" />
<CompButton v-else key="even" label="Even" />
<CompButton v-if="counter % 2" key="odd" label="Odd" :counter="counter" />
<CompButton v-else key="even" label="Even" :counter="counter" />
</keep-alive>
</StackLayout>
</Page>
Expand Down