-
Notifications
You must be signed in to change notification settings - Fork 92
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 #70 from matthewp/vbug
Use MutationObserver to teardown virtual components
- Loading branch information
Showing
8 changed files
with
154 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ before_install: | |
- "export DISPLAY=:99.0" | ||
- "sh -e /etc/init.d/xvfb start" | ||
addons: | ||
firefox: "63.0" | ||
chrome: stable |
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 @@ | ||
node_modules/lit-html |
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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<title>Haunted</title> | ||
</head> | ||
<body> | ||
<counter-app></counter-app> | ||
<script type="module"> | ||
import { html, render } from "https://unpkg.com/lit-html/lit-html.js"; | ||
import { | ||
component, | ||
useEffect, | ||
virtual, | ||
useState | ||
} from "../src/haunted.js"; | ||
|
||
const Counter = () => { | ||
useEffect(() => { | ||
console.log("connected component"); | ||
return () => { | ||
console.log("disconnected component"); | ||
}; | ||
}, []); | ||
const [count, setCount] = useState(0); | ||
|
||
return html` | ||
<button type="button" @click="${() => setCount(count + 1)}"> | ||
Count: ${count} | ||
</button> | ||
`; | ||
}; | ||
|
||
customElements.define("component-counter", component(Counter)); | ||
|
||
const Main = () => { | ||
const [show, toggle] = useState(true); | ||
const [show2, toggle2] = useState(true); | ||
return html` | ||
Component: | ||
<button @click="${() => toggle(!show)}">${show ? "Hide" : "Show"}</button> | ||
${ | ||
show | ||
? html` | ||
<component-counter></component-counter> | ||
` | ||
: undefined | ||
} <br /><br /> | ||
Virtual: | ||
<button @click="${() => toggle2(!show2)}"> | ||
${show2 ? "Hide" : "Show"} | ||
</button> | ||
${show2 ? virtual(Counter)() : undefined} | ||
`; | ||
}; | ||
|
||
customElements.define("counter-app", component(Main)); | ||
|
||
</script> | ||
</body> | ||
</html> |
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,8 @@ | ||
{ | ||
"browser": "chrome", | ||
"args": [ | ||
"--headless", | ||
"--disable-gpu", | ||
"--remote-debugging-port=9222" | ||
] | ||
} |