-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the render event dispatched on roots
- Loading branch information
Showing
11 changed files
with
1,490 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import html from "../index"; | ||
import { connect } from "./store"; | ||
|
||
import TextInput from "./TextInput"; | ||
import CharCounter from "./CharCounter"; | ||
|
||
export default function App(tasks) { | ||
return html` | ||
${TextInput()} | ||
${CharCounter()} | ||
`; | ||
} |
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,10 @@ | ||
import html from "../index"; | ||
import { connect } from "./store"; | ||
|
||
function CharCounter({value}) { | ||
return html` | ||
<div>Characters typed: ${value.length}</div> | ||
`; | ||
} | ||
|
||
export default connect(CharCounter); |
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,11 @@ | ||
# innerself example 03 | ||
|
||
An example illustrating how much hand-holding innerself needs to handle | ||
form-based elements. Because the assignment to innerHTML completely re-creates | ||
the entire DOM tree under the root, all local state of the descendant elements | ||
is lost upop re-render. Focus and selection need to be restored manually. | ||
|
||
To install the dependencies and serve the example locally run: | ||
|
||
$ npm install | ||
$ npm start |
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,12 @@ | ||
import html from "../index"; | ||
import { connect } from "./store"; | ||
|
||
function TextInput({value}) { | ||
return html` | ||
<textarea id="text-input" | ||
placeholder="Type here…" | ||
onkeyup="dispatch('CHANGE_VALUE', this)">${value}</textarea> | ||
`; | ||
} | ||
|
||
export default connect(TextInput); |
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 @@ | ||
<!doctype html> | ||
<meta charset="utf8"> | ||
<title>innerself example 03</title> | ||
<script defer src="dist.js"></script> | ||
|
||
<h1>innerself example 03</h1> | ||
<div id="root"> | ||
|
||
|
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,17 @@ | ||
import { attach } from "./store"; | ||
import App from "./App"; | ||
|
||
const root = document.querySelector("#root"); | ||
root.addEventListener("render", function(event) { | ||
// event.detail is the state that was rendered. | ||
const { id, selectionStart, selectionEnd } = event.detail; | ||
if (id) { | ||
const textarea = root.querySelector("#" + id); | ||
textarea.focus(); | ||
textarea.setSelectionRange(selectionStart, selectionEnd); | ||
} | ||
}); | ||
|
||
attach(App, root); | ||
|
||
|
Oops, something went wrong.