File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ ///
2
+ NOTE: This code looks like the typical "async-await"
3
+ style of code in JS, ported to Foi. In particular,
4
+ this example shows off the ~<< do-comprehension
5
+ syntax. The :: below are kind of like "await".
6
+ ///
7
+
8
+
9
+ defn renderLargeOrders() ^Promise ~<< {
10
+ def orders:: fetch("/all-orders");
11
+ def largeOrders: orders ~filter (order) { order.total ?>= 100; };
12
+ def customers:: all(
13
+ largeOrders ~map (order) {
14
+ fetch(\`"/customer/id/`order.custId`");
15
+ }
16
+ );
17
+ def records: largeOrders ~map (order,idx) {
18
+ < &order, customer: customers[idx] >;
19
+ };
20
+ \`"<ul>`
21
+ (| ~fold records, "", (html,record) { html + \`"
22
+ <li id=""order-`record.orderId`"">
23
+ <span>Order #`record.orderId`</span>
24
+ <span>Total: $`format(record.total)`</span>
25
+ <span>Customer: `record.customer.name` (`record.custId`)</span>
26
+ </li>
27
+ "; } |)
28
+ `</ul>";
29
+ };
30
+
31
+ renderLargeOrders()
32
+ ~map (html) { document.body.innerHTML := html; };
You can’t perform that action at this time.
0 commit comments