File tree Expand file tree Collapse file tree 5 files changed +64
-2
lines changed
Expand file tree Collapse file tree 5 files changed +64
-2
lines changed Original file line number Diff line number Diff line change 11# Anathema guide
22
3- A guide to using the Anathema TUI library.
3+ [ The Guide ] ( https://togglebyte.github.io/anathema- guide/ ) to using the Anathema TUI library.
Original file line number Diff line number Diff line change 1313- [ Templates] ( ./templates.md )
1414 - [ Loops] ( ./templates/loops.md )
1515 - [ If / Else] ( ./templates/if-else.md )
16+ - [ Either] ( ./templates/either.md )
1617 - [ Switch / Case] ( ./templates/switch-case.md )
1718 - [ With] ( ./templates/with.md )
1819 - [ Functions] ( ./templates/functions.md )
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ text "`ident` in the component attributes: " attributes.ident
7979Some elements can have one or more children.
8080
8181Example: a border element with a text element inside
82+
8283```
8384border
8485 text "look, a border"
@@ -88,11 +89,13 @@ border
8889* [ If / Else] ( ./templates/if-else.md )
8990* [ Switch / Case] ( ./templates/switch-case.md )
9091
91-
9292## Either
9393
9494The ` ? ` symbol can be used to have a fallback value.
9595
96+ See [ Either] ( ./templates/either.md ) for specifics on how this works as the
97+ behaviour differs between static values (defined in templates) and dynamic values (such as attributes and states).
98+
9699```
97100text state.maybe_value ? attributes.maybe_this ? "there was no value"
98101```
Original file line number Diff line number Diff line change 1+ # Either
2+
3+ The Either operator: ` ? ` can be used to provide fallback values.
4+
5+ Only dynamic values (attributes and state) are subject to truthiness
6+ checks; Static values (defined using ` let ` in a template) are never (even if they are false).
7+
8+ ```
9+ Does this exist?
10+ and is it truthy?
11+ / \
12+ / \
13+ yes no -------+
14+ | |
15+ V V
16+ text state.value ? "default"
17+ ```
18+
19+ ## Example
20+
21+ This will always use the static value, and print ` false ` :
22+
23+ ```
24+ text false ? "hello"
25+ ```
26+ However
27+ ```
28+ text state.maybe_false ? "hello"
29+ ```
30+
31+ Would print ` hello ` ** if** ` maybe_false ` is any of the values in the [ fallback table] ( ./either.md#fallback-table ) :
32+
33+ ### Fallback table
34+
35+ These values causes fallback.
36+
37+ * ` null `
38+ * ` 0 `
39+ * ` "" `
40+ * ` [] `
41+ * ` {} `
42+ * ` false `
43+
44+ This means that any state or attribute value that resolves to a value listed
45+ above will use the fallback.
Original file line number Diff line number Diff line change 11# Switch / Case
2+
3+ It's possible to use ` switch ` / ` case ` to determine what elements to render.
4+
5+ The ` default ` branch has to be the last one, and is not required.
6+
7+ ## Example
8+
9+ ```
10+ switch value
11+ case 1: text "one"
12+ case 2: text "two"
13+ default: text "default"
14+ ```
You can’t perform that action at this time.
0 commit comments