-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
342a3e7
commit bc745f1
Showing
15 changed files
with
177 additions
and
28 deletions.
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,82 @@ | ||
var ELEMENT_NODE = 1; | ||
var TEXT_NODE = 3; | ||
var COMMENT_NODE = 8; | ||
var COMPONENT_NODE = 2; | ||
|
||
function pairComponentNodes(startNode, endNode, vDocumentFragment) { | ||
function pairComponentNodesHelper(realNode, vComponentNode) { | ||
var component = vComponentNode.___component; | ||
var commentPlaceholder; | ||
var previousSibling; | ||
var vComponentFirstChild = vComponentNode.___firstChild; | ||
|
||
if (!vComponentFirstChild) { | ||
// Target component does not have any children. We still need | ||
// to assign it with a DOM node so we will create a placeholder | ||
commentPlaceholder = document.createComment('$marko'); | ||
realNode.parentNode.insertBefore(commentPlaceholder, realNode); | ||
component.___startNode = component.___endNode = commentPlaceholder; | ||
|
||
// Continue pairing from the current DOM node that was already in | ||
// the DOM: | ||
return realNode; | ||
} | ||
|
||
var vFirstChildType = vComponentFirstChild.___nodeType; | ||
if (vFirstChildType === COMPONENT_NODE) { | ||
// The first child of this component is another component. We need | ||
// our own DOM start node so we will have to create placeholder | ||
// and use that | ||
commentPlaceholder = document.createComment('$marko'); | ||
realNode.parentNode.insertBefore(commentPlaceholder, realNode); | ||
component.___startNode = commentPlaceholder; | ||
|
||
// Go ahead and pair the child component and we will continue | ||
// pairing with the next DOM node after the component | ||
previousSibling = pairComponentNodesHelper(realNode, vComponentFirstChild); | ||
realNode = previousSibling.nextSibling; | ||
} else { | ||
previousSibling = component.___startNode = realNode; | ||
|
||
realNode = realNode.nextSibling; | ||
} | ||
|
||
|
||
// We paired up the start node. Now we need to pair up the end nodes | ||
|
||
var vCurrentNode = vComponentFirstChild.___nextSibling; | ||
var vNextSibling; | ||
|
||
while(vCurrentNode && realNode) { | ||
var vNodeType = vCurrentNode.___nodeType; | ||
vNextSibling = vCurrentNode.___nextSibling; | ||
|
||
if (vNodeType === COMPONENT_NODE) { | ||
previousSibling = pairComponentNodesHelper(realNode, vComponentFirstChild); | ||
realNode = previousSibling.nextSibling; | ||
} else { | ||
if (vNextSibling) { | ||
realNode = realNode.nextSibling; | ||
} else { | ||
// We reached the last vNode of the component and that means | ||
// that the current real DOM node is the end node for this | ||
// component | ||
return (component.___endNode = realNode); | ||
} | ||
} | ||
|
||
previousSibling = realNode; | ||
vCurrentNode = vNextSibling; | ||
} | ||
|
||
commentPlaceholder = document.createComment('$marko'); | ||
realNode.parentNode.insertBefore(commentPlaceholder, previousSibling.nextSibling); | ||
component.___endNode = commentPlaceholder; | ||
|
||
return commentPlaceholder; | ||
} | ||
|
||
pairComponentNodesHelper(startNode.nextSibling, vDocumentFragment.___firstChild); | ||
} | ||
|
||
module.exports = pairComponentNodes; |
4 changes: 4 additions & 0 deletions
4
test/autotests/components-browser/nesting/components/a/index.marko
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,4 @@ | ||
class { | ||
} | ||
|
||
<b model={}/> |
5 changes: 5 additions & 0 deletions
5
test/autotests/components-browser/nesting/components/b/index.marko
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,5 @@ | ||
class { | ||
} | ||
|
||
<c/> |
5 changes: 5 additions & 0 deletions
5
test/autotests/components-browser/nesting/components/c/index.marko
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,5 @@ | ||
class { | ||
} | ||
|
||
<d/> | ||
<d/> |
4 changes: 4 additions & 0 deletions
4
test/autotests/components-browser/nesting/components/d/index.marko
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,4 @@ | ||
class { | ||
} | ||
|
||
<div.d/> |
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,7 @@ | ||
class { | ||
} | ||
|
||
<div.root> | ||
<a /> | ||
</div> |
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,5 @@ | ||
module.exports = function(helpers) { | ||
var component = helpers.mount(require('./index'), { }); | ||
component.forceUpdate(); | ||
component.update(); | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/autotests/components-pages/nesting/components/a/index.marko
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,7 @@ | ||
class { | ||
onMount() { | ||
window.app = this; | ||
} | ||
} | ||
|
||
<b model={} key="b"/> |
5 changes: 5 additions & 0 deletions
5
test/autotests/components-pages/nesting/components/b/index.marko
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,5 @@ | ||
class { | ||
} | ||
|
||
<c key="c"/> |
5 changes: 5 additions & 0 deletions
5
test/autotests/components-pages/nesting/components/c/index.marko
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,5 @@ | ||
class { | ||
} | ||
|
||
<d key="d1"/> | ||
<d key="d2"/> |
4 changes: 4 additions & 0 deletions
4
test/autotests/components-pages/nesting/components/d/index.marko
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,4 @@ | ||
class { | ||
} | ||
|
||
<div.d/> |
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,23 @@ | ||
lasso-page dependencies=input.browserDependencies lasso=input.lasso | ||
|
||
<!DOCTYPE html> | ||
html lang="en" | ||
head | ||
meta charset="UTF-8" | ||
title -- Marko Test | ||
lasso-head | ||
body | ||
|
||
div id="test" | ||
div id="mocha" | ||
div id="testsTarget" | ||
|
||
lasso-body | ||
|
||
<a key="a"/> | ||
|
||
init-components immediate | ||
|
||
lasso-slot name="mocha-run" | ||
|
||
browser-refresh |
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,9 @@ | ||
var path = require('path'); | ||
|
||
describe(path.basename(__dirname), function() { | ||
it('should allow diffing html', function() { | ||
var app = window.app; | ||
app.forceUpdate(); | ||
app.update(); | ||
}); | ||
}); |