summaryrefslogtreecommitdiff
path: root/tests/typ/meta/state.typ
blob: 86dc70a56fd5e7862fac84b28f8f486bc10c1166 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Test state.

---
#let s = state("hey", "a")
#let double(it) = 2 * it

#s.update(double)
#s.update(double)
$ 2 + 3 $
#s.update(double)

Is: #s.display(),
Was: #locate(location => {
  let it = query(math.equation, location).first()
  s.at(it.location())
}).

---
// Try same key with different initial value.
#state("key", 2).display()
#state("key").update(x => x + 1)
#state("key", 2).display()
#state("key", 3).display()
#state("key").update(x => x + 1)
#state("key", 2).display()

---
#set page(width: 200pt)
#set text(8pt)

#let ls = state("lorem", lorem(1000).split("."))
#let loremum(count) = {
  ls.display(list => list.slice(0, count).join(".").trim() + ".")
  ls.update(list => list.slice(count))
}

#let fs = state("fader", red)
#let trait(title) = block[
  #fs.display(color => text(fill: color)[
    *#title:* #loremum(1)
  ])
  #fs.update(color => color.lighten(30%))
]

#trait[Boldness]
#trait[Adventure]
#trait[Fear]
#trait[Anger]

---
// Make sure that a warning is produced if the layout fails to converge.
// Warning: layout did not converge within 5 attempts
// Hint: check if any states or queries are updating themselves
#let s = state("s", 1)
#locate(loc => s.update(s.final(loc) + 1))
#s.display()