2222from great_tables import GT
2323from great_tables .data import reactions
2424
25+ from datastar_py import attribute_generator as data
2526from datastar_py .fasthtml import DatastarResponse , ServerSentEventGenerator
2627
2728######################################################################################################
4243app , rt = fast_app (
4344 htmx = False ,
4445 surreal = False ,
45- live = True ,
46+ live = False ,
4647 hdrs = (
4748 Script (
4849 type = "module" ,
@@ -133,14 +134,12 @@ def index():
133134 ),
134135 ),
135136 # When the below request is in flight, $filtering becomes true, setting the aria-busy attribute
136- Label ({ " data- attr: aria-busy" : "$filtering" }, fr = "filter" )("Filter Compound" ),
137+ Label (data . attr ({ " aria-busy" : "$filtering" }) , fr = "filter" )("Filter Compound" ),
137138 # Bind the 'filter' signal to the value of this input, debouncing using Datastar modifier
138139 Input (
139- {
140- "data-on:input__debounce.250ms" : f"@post('{ table } ')" ,
141- "data-bind:filter" : True ,
142- "data-indicator:filtering" : True ,
143- },
140+ data .on ("input" , f"@post('{ table } ')" ).debounce ("250ms" ),
141+ data .bind ("filter" ),
142+ data .indicator ("filtering" ),
144143 id = "filter" ,
145144 name = "filter" ,
146145 ),
@@ -177,12 +176,11 @@ async def _():
177176async def reset ():
178177 reset_and_hello = Div (id = "myElement" )(
179178 Button (
180- {
181- "data-on:click" : f"@get('{ hello } ')" ,
182- "data-indicator:resetting" : True ,
183- "data-attr:aria-busy" : "$resetting" ,
184- "data-attr:disabled" : "$resetting" ,
185- },
179+ # Attributes can either be defined using the Datastar SDK's
180+ # attribute_generator or with dicts as in HELLO_BUTTON below
181+ data .on ("click" , f"@get('{ hello } ')" ),
182+ data .indicator ("resetting" ),
183+ data .attr ({"aria-busy" : "$resetting" , "disabled" : "$resetting" }),
186184 type = "reset" ,
187185 )("Reset" ),
188186 Div ("Hello!" ),
@@ -200,7 +198,7 @@ async def _():
200198 Button (
201199 {
202200 "data-on:click" : f"@get('{ reset } ')" ,
203- "data-indicator:loading " : True ,
201+ "data-indicator" : "loading" ,
204202 "data-attr:aria-busy" : "$loading" ,
205203 "data-attr:disabled" : "$loading" ,
206204 }
0 commit comments