From 7e812e64989773e87eddb24edf4a3cd74af1c480 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 27 Nov 2025 20:34:33 +0100 Subject: [PATCH 1/3] Format --- demos/BookstoreApp.res | 64 +++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/demos/BookstoreApp.res b/demos/BookstoreApp.res index 8bb937c..2a79589 100644 --- a/demos/BookstoreApp.res +++ b/demos/BookstoreApp.res @@ -338,7 +338,8 @@ let header = () => { } else { "hidden" } - }> + } + > {Component.textSignal(() => Int.toString(Signal.get(cartItemCount)))} , ], @@ -374,7 +375,8 @@ let homePage = () => {
+ class="bg-white dark:bg-stone-800 rounded-xl p-6 border-2 border-stone-200 dark:border-stone-700" + >
{Component.text("📖")}

{Component.text("12 Unique Titles")} @@ -384,7 +386,8 @@ let homePage = () => {

+ class="bg-white dark:bg-stone-800 rounded-xl p-6 border-2 border-stone-200 dark:border-stone-700" + >
{Component.text("🎨")}

{Component.text("Fictional Authors")} @@ -394,7 +397,8 @@ let homePage = () => {

+ class="bg-white dark:bg-stone-800 rounded-xl p-6 border-2 border-stone-200 dark:border-stone-700" + >
{Component.text("Æ‘")}

{Component.text("Functor Currency")} @@ -414,7 +418,8 @@ let aboutPage = () => { {Component.text("About Functional Bookstore")}

+ class="bg-white dark:bg-stone-800 rounded-xl p-8 border-2 border-stone-200 dark:border-stone-700 space-y-6" + >

{Component.text( "Welcome to the Functional Bookstore, your one-stop shop for the most absurd and delightful functional programming literature in the known universe.", @@ -471,7 +476,8 @@ let productCard = (props: productCardProps) => { })

+ class="bg-white dark:bg-stone-800 rounded-xl p-6 shadow-lg hover:shadow-xl transition-shadow border-2 border-stone-200 dark:border-stone-700" + >
{Component.text(props.product.cover)}

{Component.text(props.product.title)} @@ -493,7 +499,8 @@ let productCard = (props: productCardProps) => { } else { "px-4 py-2 bg-stone-900 hover:bg-stone-700 dark:bg-stone-700 dark:hover:bg-stone-600 text-white rounded-lg font-semibold transition-colors" }} - onClick={_ => addToCart(props.product.id)}> + onClick={_ => addToCart(props.product.id)} + > {Component.textSignal(() => if Signal.get(inCart) { "✓ In Cart" @@ -527,7 +534,8 @@ let cartItemRow = (props: cartItemRowProps) => { switch product { | Some(p) =>
+ class="bg-white dark:bg-stone-800 rounded-lg p-4 shadow border-2 border-stone-200 dark:border-stone-700" + >
{Component.text(p.cover)}
@@ -543,16 +551,19 @@ let cartItemRow = (props: cartItemRowProps) => {
+ class="px-4 py-1 bg-stone-100 dark:bg-stone-700 rounded font-semibold text-stone-900 dark:text-white" + > {Component.text(Int.toString(props.item.quantity))}
@@ -561,7 +572,8 @@ let cartItemRow = (props: cartItemRowProps) => {

@@ -585,7 +597,8 @@ let cartView = () => { "block" } else { "hidden" - }}> + }} + >

{Component.text("Your cart is empty")} @@ -609,12 +622,12 @@ let cartView = () => { "hidden" } else { "block" - }}> -

- {Component.list(cart, item => cartItemRow({item: item}))} -
+ }} + > +
{Component.list(cart, item => cartItemRow({item: item}))}
+ class="bg-stone-100 dark:bg-stone-800 rounded-lg p-6 border-2 border-stone-300 dark:border-stone-700" + >
{Component.text("Total:")} @@ -664,7 +677,8 @@ let checkoutView = () => { {Component.text("Checkout")}

+ class="bg-white dark:bg-stone-800 rounded-xl p-6 shadow-lg border-2 border-stone-200 dark:border-stone-700 mb-6" + >

{Component.text("Shipping Information")}

@@ -716,7 +730,8 @@ let checkoutView = () => {
+ class="bg-white dark:bg-stone-800 rounded-xl p-6 shadow-lg border-2 border-stone-200 dark:border-stone-700 mb-6" + >

{Component.text("Payment Information")}

@@ -733,7 +748,8 @@ let checkoutView = () => {
+ class="bg-stone-100 dark:bg-stone-800 rounded-lg p-6 border-2 border-stone-300 dark:border-stone-700 mb-6" + >
{Component.textSignal(() => "Items (" ++ Int.toString(Signal.get(cartItemCount)) ++ ")")} @@ -773,7 +789,8 @@ let checkoutView = () => { )}
@@ -784,7 +801,8 @@ let checkoutView = () => { let orderConfirmedView = () => {
+ class="bg-white dark:bg-stone-800 rounded-xl p-8 shadow-lg border-2 border-stone-300 dark:border-stone-700 text-center" + >
{Component.text("✅")}

{Component.text("Order Confirmed!")} From fc794970e5b35139f03609cfc808df6a24c35cd5 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 27 Nov 2025 20:16:49 +0100 Subject: [PATCH 2/3] Use @jsx.component # Conflicts: # demos/BookstoreApp.res --- demos/BookstoreApp.res | 89 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/demos/BookstoreApp.res b/demos/BookstoreApp.res index 2a79589..85d466f 100644 --- a/demos/BookstoreApp.res +++ b/demos/BookstoreApp.res @@ -466,51 +466,52 @@ let aboutPage = () => {

} -/* ProductCard Component using JSX */ -type productCardProps = {product: product} +module ProductCard = { + /* ProductCard Component using JSX */ + @jsx.component + let make = (~product: product) => { + let inCart = Computed.make(() => { + let item = getCartItem(product.id) + Option.isSome(item) + }) -let productCard = (props: productCardProps) => { - let inCart = Computed.make(() => { - let item = getCartItem(props.product.id) - Option.isSome(item) - }) - -
-
{Component.text(props.product.cover)}
-

- {Component.text(props.product.title)} -

-

- {Component.text("by " ++ props.product.author)} -

-

- {Component.text(props.product.description)} -

-
- - {Component.text(formatPrice(props.product.price))} - - +
+
{Component.text(product.cover)}
+

+ {Component.text(product.title)} +

+

+ {Component.text("by " ++ product.author)} +

+

+ {Component.text(product.description)} +

+
+ + {Component.text(formatPrice(product.price))} + + +
-
+ } } /* CatalogView Component using JSX */ @@ -520,7 +521,7 @@ let catalogView = () => { {Component.text("Available Books")}
- {Component.fragment(products->Array.map(product => productCard({product: product})))} + {Component.fragment(products->Array.map(product => ))}
} From 260ac7171d2c51e898e37fe8fdec239fff2dc270 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 27 Nov 2025 20:26:43 +0100 Subject: [PATCH 3/3] Use JSX.array --- demos/BookstoreApp.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/BookstoreApp.res b/demos/BookstoreApp.res index 85d466f..6ca0a8c 100644 --- a/demos/BookstoreApp.res +++ b/demos/BookstoreApp.res @@ -521,7 +521,7 @@ let catalogView = () => { {Component.text("Available Books")}
- {Component.fragment(products->Array.map(product => ))} + {products->Array.map(product => )->JSX.array}
}