Skip to content

Commit 5c95510

Browse files
committed
docs: improve hello world section; slices→substate.
1 parent 7aeffb3 commit 5c95510

14 files changed

+121
-208
lines changed

docs/CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Thank you for taking the time to read our contribution guidelines. You can start
44

55
## Style
66

7-
* We write in ES5.
7+
* Hyperapp is written in ES5.
88
* Format your code before creating a new commit using `npm run format`.
99
* We prefer keeping all the moving parts inside as few files as possible. We don't have plans to break up the library into smaller modules.
1010

1111
## Bugs
1212

1313
* Before submitting a bug report, search the issues for similar tickets. Your issue may have already been discussed and resolved. Feel free to add a comment to an existing ticket, even if it's closed.
1414
* Determine which repository the problem should be reported in. If you have an issue with the Router, you'll be better served in [hyperapp/router](https://github.com/hyperapp/router), etc.
15-
* If you have a question or need help with something you are building, we recommend joining the [Hyperapp Slack Team](https://hyperappjs.herokuapp.com).
15+
* If you have a question or need help with something you are building, hop on [Slack](https://hyperappjs.herokuapp.com).
1616
* Be thorough in your title and report, don't leave out important details, describe your setup and include any relevant code with your issue.
1717
* Use GitHub [fenced code blocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/) when sharing code. If your code has JSX in it, please use <code>```jsx</code> for best syntax highlighting.
1818

@@ -24,4 +24,4 @@ Thank you for taking the time to read our contribution guidelines. You can start
2424

2525
## Humans
2626

27-
Our open source community strives to be nice, welcoming and professional. Instances of abusive, harassing, or otherwise unacceptable behavior can be reported by contacting us at <mailto:[email protected]>.
27+
Our open source community strives to be nice, welcoming and professional. Instances of abusive, harassing, or otherwise unacceptable behavior can be reported by contacting us at [[email protected]]([email protected]).

docs/README.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# Documentation
22

3-
- [Introduction](introduction/README.md)
4-
- [Hello World](introduction/hello-world.md)
5-
- [Installation](introduction/installation.md)
6-
- [Concepts](concepts/README.md)
7-
- [Virtual Nodes](concepts/vnodes.md)
8-
- [Components](concepts/components.md)
9-
- [Lifecycle Events](concepts/lifecycle-events.md)
10-
- [Keys](concepts/keys.md)
11-
- [Slices](concepts/slices.md)
12-
- [Sanitation](concepts/sanitation.md)
13-
- [Hydration](concepts/hydration.md)
14-
- [Tutorials](tutorials/README.md)
15-
- [TweetBox](tutorials/tweetbox.md)
16-
- [Gif Search](tutorials/gif-search.md)
17-
- [Countdown Timer](tutorials/countdown-timer.md)
18-
- [Contributing](CONTRIBUTING.md)
3+
* [Introduction](introduction/README.md)
4+
* [Hello World](introduction/hello-world.md)
5+
* [Installation](introduction/installation.md)
6+
* [Concepts](concepts/README.md)
7+
* [Virtual Nodes](concepts/vnodes.md)
8+
* [Keys](concepts/keys.md)
9+
* [Components](concepts/components.md)
10+
* [Lifecycle Events](concepts/lifecycle-events.md)
11+
* [Sanitation](concepts/sanitation.md)
12+
* [Hydration](concepts/hydration.md)
13+
* [Tutorials](tutorials/README.md)
14+
* [TweetBox](tutorials/tweetbox.md)
15+
* [Gif Search](tutorials/gif-search.md)
16+
* [Countdown Timer](tutorials/countdown-timer.md)
17+
* [Contributing](CONTRIBUTING.md)

docs/SUMMARY.md

-19
This file was deleted.

docs/concepts/README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
## Concepts
22

3-
- [Virtual Nodes](vnodes.md)
4-
- [Components](components.md)
5-
- [Lifecycle Events](lifecycle-events.md)
6-
- [Keys](keys.md)
7-
- [Slices](slices.md)
8-
- [Sanitation](sanitation.md)
9-
- [Hydration](hydration.md)
3+
* [Virtual Nodes](vnodes.md)
4+
* [Keys](keys.md)
5+
* [Components](components.md)
6+
* [Lifecycle Events](lifecycle-events.md)
7+
* [Sanitation](sanitation.md)
8+
* [Hydration](hydration.md)

docs/concepts/hydration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ Hyperapp works transparently with SSR and pre-rendered HTML, enabling SEO optimi
1818
</html>
1919
```
2020

21-
Then instead of throwing away the server-rendered markdown, we'll turn your DOM nodes into an interactive application.
21+
Then instead of throwing away the server-rendered markdown, we'll turn your DOM nodes into an interactive application out of the box!

docs/concepts/keys.md

+15-21
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,26 @@
33
Keys help identify which nodes were added, changed or removed from a list when a view is rendered. A key must be unique among sibling-nodes.
44

55
```jsx
6-
const ImageGallery = ({ images }) => (
7-
<ul>
8-
{images.map(({ hash, url, description }) => (
9-
<li key={hash}>
10-
<img src={url} alt={description} />
11-
</li>
12-
))}
13-
</ul>
14-
)
6+
const ImageGallery = ({ images }) =>
7+
images.map(({ hash, url, description }) => (
8+
<li key={hash}>
9+
<img src={url} alt={description} />
10+
</li>
11+
))
1512
```
1613

1714
By setting the `key` property on a virtual node, you declare that the node should correspond to a particular DOM element. This allow us to re-order the element into its new position, if the position changed, rather than risk destroying it.
1815

1916
Don't use an array index as key, if the index also specifies the order of siblings. If the position and number of items in a list is fixed, it will make no difference, but if the list is dynamic, the key will change every time the tree is rebuilt.
2017

2118
```jsx
22-
const PlayerList = ({ players }) => (
23-
<ul>
24-
{players
25-
.slice()
26-
.sort((player, nextPlayer) => nextPlayer.score - item.score)
27-
.map(player => (
28-
<li key={player.username} class={player.isAlive ? "alive" : "dead"}>
29-
<PlayerCard {...player} />
30-
</li>
31-
))}
32-
</ul>
33-
)
19+
const PlayerList = ({ players }) =>
20+
players
21+
.slice()
22+
.sort((player, nextPlayer) => nextPlayer.score - item.score)
23+
.map(player => (
24+
<li key={player.username} class={player.isAlive ? "alive" : "dead"}>
25+
<PlayerCard {...player} />
26+
</li>
27+
))
3428
```

docs/concepts/lifecycle-events.md

+18-22
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,31 @@ You can be notified when a virtual node is created, updated or removed via lifec
77
This event is fired after the element is created and attached to the DOM. Use it to manipulate the DOM node directly, make a network request, create slide/fade in animation, etc.
88

99
```jsx
10-
function Textbox({ placeholder }) {
11-
return (
12-
<input
13-
type="text"
14-
placeholder={placeholder}
15-
oncreate={element => element.focus()}
16-
/>
17-
)
18-
}
10+
const Textbox = ({ placeholder }) => (
11+
<input
12+
type="text"
13+
placeholder={placeholder}
14+
oncreate={element => element.focus()}
15+
/>
16+
)
1917
```
2018

2119
## onupdate
2220

2321
This event is fired every time we update the element attributes. Use `oldProps` inside the event handler to check if any attributes changed or not.
2422

2523
```jsx
26-
function Textbox({ placeholder }) {
27-
return (
28-
<input
29-
type="text"
30-
placeholder={placeholder}
31-
onupdate={(element, oldProps) => {
32-
if (oldProps.placeholder !== placeholder) {
33-
// Handle changes here!
34-
}
35-
}}
36-
/>
37-
)
38-
}
24+
const Textbox = ({ placeholder }) => (
25+
<input
26+
type="text"
27+
placeholder={placeholder}
28+
onupdate={(element, oldProps) => {
29+
if (oldProps.placeholder !== placeholder) {
30+
// Handle changes here!
31+
}
32+
}}
33+
/>
34+
)
3935
```
4036

4137
## onremove

docs/concepts/sanitation.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
Use of the innerHTML method can lead to cross-site scripting ([XSS](https://en.wikipedia.org/wiki/Cross-site_scripting)) vunerabilities if not properly sanitized. If you can't use vnodes for any reason, create your own replacement function to explicitly state the intent of performing an "unsafe" operation.
44

55
```jsx
6-
function dangerouslySetInnerHTML(html) {
7-
return element => {
8-
element.innerHTML = html
9-
}
6+
const dangerouslySetInnerHTML = html => element => {
7+
element.innerHTML = html
108
}
119

12-
function ItemContent({ item: { url, summary } }) {
13-
return (
14-
<div class="content">
15-
<a href={url} oncreate={dangerouslySetInnerHTML(summary)} />
16-
</div>
17-
)
18-
}
10+
const ItemContent = ({ item: { url, summary } }) => (
11+
<div class="content">
12+
<a href={url} oncreate={dangerouslySetInnerHTML(summary)} />
13+
</div>
14+
)
1915
```
2016

21-
Setting HTML from code is dangerous because it's easy to inadvertently expose your users to an XSS attack. [DOMPurify](https://github.com/cure53/DOMPurify) and [sanitize-html](https://github.com/punkave/sanitize-html) are two popular HTML sanitizer libraries.
17+
Use with caution! Setting HTML from code is dangerous because it's easy to inadvertently expose your users to an XSS attack. [DOMPurify](https://github.com/cure53/DOMPurify) and [sanitize-html](https://github.com/punkave/sanitize-html) are two popular HTML sanitizer libraries.

docs/concepts/slices.md

-84
This file was deleted.

docs/concepts/vnodes.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,7 @@ To create a virtual node, use the `h` function.
2222
const node = h("div", { id: "app" }, [h("h1", {}, "Hi.")])
2323
```
2424

25-
Alternatives to the built-in `h()` function include [JSX](https://facebook.github.io/jsx/), [hyperx](https://github.com/choojs/hyperx), [t7](https://github.com/trueadm/t7) and [@hyperapp/html](https://github.com/hyperapp/html).
26-
27-
```jsx
28-
const node = (
29-
<div id="app">
30-
<h1>Hi.</h1>
31-
</div>
32-
)
33-
```
34-
35-
Virtual node props may include any valid [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes) or [SVG](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute) attributes, [DOM](https://developer.mozilla.org/en-US/docs/Web/Events), [lifecycle events](lifecycle-events.md), and [keys](keys.md).
25+
Virtual node props may include any valid [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes) and [SVG](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute) attributes, [DOM events](https://developer.mozilla.org/en-US/docs/Web/Events), [lifecycle events](lifecycle-events.md), and [keys](keys.md).
3626

3727
```jsx
3828
const button = (

docs/introduction/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## Introduction
22

3-
- [Hello World](hello-world.md)
4-
- [Installation](installation.md)
3+
* [Hello World](hello-world.md)
4+
* [Installation](installation.md)

0 commit comments

Comments
 (0)