Skip to content

Commit 63c9f0b

Browse files
committed
Move VDOM types doc from TYPES.md to VDOM.md
1 parent ce4e94b commit 63c9f0b

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

doc/TYPES.md

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -308,31 +308,4 @@ on a link should open in a new tab.
308308

309309
# VDOM
310310

311-
The two most important types are `VdomElement` and `TagMod`.
312-
313-
| Type | Explaination |
314-
| ---- | ---- |
315-
| `VdomElement` | A single VDOM tag. This can be a tag like `<div>` or a component. <br> This is the result of components' `.render` methods. |
316-
| `VdomNode` | A single piece of VDOM. Can be a `VdomElement`, or a piece of text, a number, etc. |
317-
| `VdomArray` | An array of VDOM nodes. <br> This is passed to React as an array which helps Reacts diff'ing mechanism. React also requires that each array element have a key. |
318-
| `VdomAttr` | A tag attribute (including styles). <br> Examples: `href`, `value`, `onClick`, `margin`. |
319-
| `VdomTagOf[Node]` | A HTML or SVG tag of type `Node`. |
320-
| `VdomTag` | A HTML or SVG tag. |
321-
| `HtmlTagOf[Node]` | A HTML tag of type `Node`. |
322-
| `HtmlTag` | A HTML tag. |
323-
| `SvgTagOf[Node]` | An SVG tag of type `Node`. |
324-
| `SvgTag` | An SVG tag. |
325-
| `TagMod` | Tag-Modifier. A modification to a `VdomTag`. All of the types here can be a `TagMod` because they can all be used to modify a `VdomTag`. <br> This is ***very useful*** for reuse and abstraction in practice, very useful for separating DOM functionality, asthetics and content. <br> For example, it allows a function to return a child tag, a style and some event handlers which the function caller can then apply to some external tag. |
326-
327-
Examples:
328-
```scala
329-
import japgolly.scalajs.react.vdom.all._
330-
331-
val tag1 : VdomTag = input(className := "name")
332-
val mod1 : TagMod = value := "Bob"
333-
val mod2 : TagMod = TagMod(mod1, `type` := "text", title := "hello!")
334-
val tag2 : VdomTag = tag1(mod2, readOnly := true)
335-
val element: VdomElement = tag2
336-
// equivalent to
337-
// <input class="name" value="Bob" type="text", title := "hello!" readonly=true />
338-
```
311+
VDOM types are [described here](VDOM.md#types).

doc/VDOM.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
- [Conditional VDOM](#conditional-vdom)
66
- [Collections](#collections)
77
- [Custom VDOM](#custom-vdom)
8+
- [Types](#types)
89
- [Cheatsheet](#cheatsheet)
910

1011
## Basics
1112

12-
It's important to understand the [VDOM types](TYPES.md#vdom) too so have a read.
13-
1413
There are two ways of creating virtual-DOM.
1514

1615
1. **Prefixed (recommended)** - Importing DOM tags and attributes under prefixes is recommended.
@@ -245,6 +244,38 @@ customTag(customAttr := "hello", customStyle := "123", "bye")
245244
In addition to `HtmlTag(…)`, there is also `SvgTag(…)`, `HtmlTagTo[N](…)`, `SvgTagTo[N](…)`.
246245

247246

247+
## Types
248+
249+
The most important types are probably `TagMod` and `VdomElement`.
250+
251+
| Type | Explaination |
252+
| ---- | ---- |
253+
| `VdomElement` | A single VDOM tag. <br> This can be a tag like `<div>`, or a rendered component. This is also the result of components' `.render` methods. |
254+
| `VdomNode` | A single piece of VDOM. <br> Can be a `VdomElement`, or a piece of text, a number, etc. |
255+
| `VdomArray` | An array of VDOM nodes. <br> This is passed to React as an array which helps Reacts diff'ing mechanism. React also requires that each array element have a key. |
256+
| `VdomAttr` | A tag attribute (including styles). <br> Examples: `href`, `value`, `onClick`, `margin`. |
257+
| `VdomTagOf[Node]` | A HTML or SVG tag of type `Node`. |
258+
| `VdomTag` | A HTML or SVG tag. |
259+
| `HtmlTagOf[Node]` | A HTML tag of type `Node`. |
260+
| `HtmlTag` | A HTML tag. |
261+
| `SvgTagOf[Node]` | An SVG tag of type `Node`. |
262+
| `SvgTag` | An SVG tag. |
263+
| `TagMod` | Tag-Modifier. A modification to a `VdomTag`. <br> All of the types here can be a `TagMod` because they can all be used to modify a `VdomTag`. <br> This is ***very useful*** for reuse and abstraction in practice, very useful for separating DOM functionality, asthetics and content. <br> For example, it allows a function to return a child tag, a style and some event handlers which the function caller can then apply to some external tag. |
264+
265+
Examples:
266+
```scala
267+
import japgolly.scalajs.react.vdom.all._
268+
269+
val tag1 : VdomTag = input(className := "name")
270+
val mod1 : TagMod = value := "Bob"
271+
val mod2 : TagMod = TagMod(mod1, `type` := "text", title := "hello!")
272+
val tag2 : VdomTag = tag1(mod2, readOnly := true)
273+
val element: VdomElement = tag2
274+
// equivalent to
275+
// <input class="name" value="Bob" type="text", title := "hello!" readonly=true />
276+
```
277+
278+
248279
## Cheatsheet
249280

250281
| Category | Expressions | Result Type |

0 commit comments

Comments
 (0)