-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from choojs/issue-65
Store realNode reference on proxy node
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var test = require('tape') | ||
var morph = require('nanomorph') | ||
var Nanocomponent = require('../../') | ||
var html = require('bel') | ||
|
||
function isProxy (node) { | ||
return node.dataset.proxy !== undefined | ||
} | ||
|
||
class Component extends Nanocomponent { | ||
createElement () { | ||
return html`<div>I'm a component</div>` | ||
} | ||
|
||
update () { | ||
return false | ||
} | ||
} | ||
|
||
function makeID () { | ||
return 'testid-' + Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1) | ||
} | ||
|
||
function createTestElement () { | ||
var testRoot = document.createElement('div') | ||
testRoot.id = makeID() | ||
document.body.appendChild(testRoot) | ||
return testRoot | ||
} | ||
|
||
test('should not leak proxy nodes', t => { | ||
var testRoot = createTestElement() | ||
var component = new Component() | ||
var view = viewA() | ||
var newView | ||
|
||
function viewA () { | ||
return html` | ||
<body> | ||
<a href="/">beep</a> | ||
<a href="/boop">boop</a> | ||
<div> | ||
${component.render()} | ||
</div> | ||
</body> | ||
` | ||
} | ||
|
||
function viewB () { | ||
return html` | ||
<body> | ||
<a href="/">beep</a> | ||
<a href="/boop">boop</a> | ||
${component.render()} | ||
</body> | ||
` | ||
} | ||
|
||
testRoot.appendChild(view) | ||
newView = morph(view, viewB()) | ||
t.notOk(isProxy(newView.children[2]), 'proxy node has not been leaked') | ||
t.end() | ||
}) |