This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
demo.ftd
148 lines (80 loc) · 2 KB
/
demo.ftd
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
;; let's define some page level data
-- integer $x: 10
-- integer $y: 23
-- integer list $counters:
-- integer: 1
-- integer: $x
-- integer: $y
-- integer: 42
-- end: $counters
-- integer sum: $add(a=$x, b=$y)
-- ftd.column:
spacing.fixed.px: 20
padding.px: 20
-- ftd.text: fastn demo
role: $inherited.types.heading-hero
-- ftd.text: Try it!
role: $inherited.types.copy-regular
background.solid: $inherited.colors.cta-primary.base
color: $inherited.colors.cta-primary.text
border-color: $inherited.colors.cta-primary.border
border-width.px: 1
padding-vertical.px: 5
padding-horizontal.px: 10
link: /r/counter/
-- ftd.text:
Source: [demo.ftd](https://github.com/fastn-stack/fastn.com/blob/main/demo.ftd)
[Tutorial](/tutorials/basic/).
-- counter: $c
for: $c, $i in $counters
index: $i
-- ftd.text: \$x
-- ftd.integer: $x
-- ftd.text: counter $x
-- counter: $x
-- ftd.text: counter $y
-- counter: $y
-- ftd.text: counter *$x
-- counter: *$x
-- ftd.text: add counter
$on-click$: $add-counter($c=$counters)
-- ftd.integer: $sum
;; -- ftd.integer: $the-sum(c=$counters)
-- end: ftd.column
-- component counter:
caption integer $count:
optional integer index:
integer d: $double(a=$counter.count)
-- ftd.row:
border-width.px: 2
padding.px: 20
spacing.fixed.px: 20
background.solid if { counter.count % 2 == 0 }: yellow
border-radius.px: 5
-- ftd.text: ➕
$on-click$: $ftd.increment-by($a=$counter.count, v=1)
-- ftd.integer: $counter.count
-- ftd.integer: $counter.d
-- ftd.text: ➖
$on-click$: $ftd.increment-by($a=$counter.count, v=-1)
-- ftd.text: delete
if: { counter.index != NULL }
$on-click$: $delete-counter($c=$counters, index=$counter.index)
color: red
-- end: ftd.row
-- end: counter
-- integer add(a, b):
integer a:
integer b:
a + b
-- void add-counter(c):
integer list $c:
;; https://fastn.com/built-in-functions/
ftd.append(c, 223)
-- integer double(a):
integer a:
a * 2
-- void delete-counter(c,index):
integer list $c:
integer index:
ftd.delete_at(c, index)