Skip to content

Commit 08a4aaf

Browse files
authored
Merge pull request #12 from falcoframework/task/rc_6
2 parents 5f3d39d + 8959c93 commit 08a4aaf

9 files changed

Lines changed: 72 additions & 76 deletions

File tree

README.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ Some important notes: Signals defined later in the DOM tree override those defin
126126
- [Binding to Signals](#signal-binding)
127127
- [Events and Triggers](#events-and-triggers)
128128
- [Actions and Functions](#actions-and-functions)
129-
- [Miscellaneous Actions](#miscellaneous-actions)
130-
- [When to $](#_when-to-_)
129+
- [When to $](#when-to-)
131130

132131
## _Attribute Index_
133132

@@ -136,15 +135,14 @@ Some important notes: Signals defined later in the DOM tree override those defin
136135
- [data-class](#dsclass--data-class)
137136
- [data-computed](#dscomputed--data-computed)
138137
- [data-effect](#dseffect--data-effect)
139-
- [data-ignore](#dsignore-dsignorethis-dsignoremorph--data-star-ignore)
138+
- [data-ignore](#dsignore--dsignoreself--dsignoremorph--data-star-ignore)
140139
- [data-indicator](#dsindicator--data-indicator)
141140
- [data-json-signals](#dssignals--dssignal--data-signals)
141+
- [data-init](#dsinit--data-init)
142142
- [data-on](#dsonevent--data-on)
143143
- [data-on-intersect](#dsonintersect--data-on-intersect)
144144
- [data-on-interval](#dsoninterval--data-on-interval)
145-
- [data-on-load](#dsonload--data-on-load)
146145
- [data-on-signal-patch](#dsonsignalpatch--dsonsignalpatchfilter--data-on-signal-patch)
147-
- [data-on-signal-patch-filter](#dsonsignalpatch--dsonsignalpatchfilter--data-on-signal-patch)
148146
- [data-ref](#dsref--data-ref)
149147
- [data-show](#dsshow--data-show)
150148
- [data-signals](#dssignals--dssignal--data-signals)
@@ -228,7 +226,7 @@ Example: setting the innerText of a `<div>` to a value that is updated by a serv
228226
### [Ds.bind : `data-bind`](https://data-star.dev/reference/attributes#data-bind)
229227

230228
Creates a two-way binding from a signal to the "value" of an HTML "input" element. Can be placed on any HTML element on which data can be input or choices
231-
selected (e.g. `input`, `textarea`, `select`, `checkbox` and `radio` elements, as well as web components. (Although not necessary, you can find the `switch` statement in the
229+
selected (e.g. `input`, `textarea`, `select`, `checkbox` and `radio` elements, as well as web components. Although not necessary, you can find the `switch` statement in the
232230
[source](https://github.com/starfederation/datastar/blob/main/library/src/plugins/attributes/bind.ts) to see how signals are translated).
233231
The signal will be created if it does not already exist. And the type of the signal is preserved during binding; if an element's value changes,
234232
the signal value is automatically converted to match the original (see the [documentation](https://data-star.dev/reference/attributes#data-bind) for an example.)
@@ -285,6 +283,16 @@ Elem.div [ Ds.style "display" "$hiding && 'none'" ] [ Text.raw "Might be hiding"
285283
Events and triggers result in [Datastar expressions](https://data-star.dev/guide/datastar_expressions) being executed. This can result in signal changes and other expressions being run.
286284
Example: clicking a button to send a request or an element scrolling into view.
287285

286+
### [Ds.init : `data-init`](https://data-star.dev/reference/attributes#data-init)
287+
288+
Runs an expression when the element is loaded into the DOM. **Important:** when patching elements,
289+
`ElementPatchMode.Replace` the [Datastar expression](https://data-star.dev/guide/datastar_expressions)
290+
will be fired a second time, but will not with `ElementPatchMode.Outer`.
291+
292+
```fsharp
293+
Elem.div [ Ds.init (Ds.get "/moreAgents") ] []
294+
```
295+
288296
### [Ds.onEvent : `data-on`](https://data-star.dev/reference/attributes#data-on)
289297

290298
Attaches an event listener to an element, executing a [Datastar expression](https://data-star.dev/guide/datastar_expressions) whenever the event is triggered.
@@ -297,7 +305,7 @@ Elem.div [ Ds.onEvent("mouseenter", "$show = !$show"); Ds.onEvent("mouseexit", "
297305

298306
```fsharp
299307
Elem.button [ Ds.onClick "$show = !$show" ] [ Text.raw "Peek-a-boo!" ]
300-
Elem.div [ Ds.onLoad (Ds.get "/edit") ] []
308+
Elem.div [ Ds.init (Ds.get "/edit") ] []
301309
```
302310

303311
#### `data-on` Modifiers
@@ -310,9 +318,9 @@ Modifiers allow you to alter the behavior when events are triggered. (Modifiers
310318
| Passive // * - can only be used with built-in events
311319
| Capture // * - can only be used with built-in events
312320
| Delay of TimeSpan
313-
| DelayMs of int // identical to Delay, but just milliseconds
314-
| Debounce of Debounce // timespan, leading, and notrail
315-
| Throttle of Throttle // timepan, noleading, and trail
321+
| DelayMs of int // identical to Delay, but using milliseconds instead
322+
| Debounce of Debounce // timespan, leading, and notrailing
323+
| Throttle of Throttle // timepan, noleading, and trailing
316324
| ViewTransition
317325
| Window
318326
| Outside
@@ -329,16 +337,7 @@ Elem.div [
329337

330338
Results in:
331339
```html
332-
<div data-on-click__window__debounce.1000ms.leading="$foo = ''"></div>
333-
```
334-
335-
### [Ds.onLoad : `data-on-load`](https://data-star.dev/reference/attributes#data-on-load)
336-
337-
Runs an expression when the element is loaded into the DOM. **Important:** when patching elements, `ElementPatchMode.Replace` the [Datastar expression](https://data-star.dev/guide/datastar_expressions)
338-
will be fired a second time, but will not with `ElementPatchMode.Outer`.
339-
340-
```fsharp
341-
Elem.div [ Ds.onLoad (Ds.get "/moreAgents") ] []
340+
<div data-on:click__window__debounce.1000ms.leading="$foo = ''"></div>
342341
```
343342

344343
### [Ds.effect : `data-effect`](https://data-star.dev/reference/attributes#data-effect)
@@ -367,12 +366,14 @@ Elem.div [ Ds.onIntersect ("$intersected = true", visibility = Half, onlyOnce =
367366
Elem.div [ Ds.onIntersect ("$intersected = true", visibility = Half, onlyOnce = true, throttle = Throttle.With(TimeSpan.FromSeconds(1.0))) ] []
368367
```
369368

370-
### [Ds.onSignalPatch | Ds.onSignalPatchFilter: `data-on-signal-patch`](https://data-star.dev/reference/attributes#data-on-signal-change)
369+
### [Ds.onSignalPatch | Ds.onSignalPatchFilter : `data-on-signal-patch`](https://data-star.dev/reference/attributes#data-on-signal-patch)
371370

372371
Runs an expression any signal changes. This should be used sparingly, as it is cost intensive.
373372

374373
```fsharp
375-
Elem.div [ Ds.onAnySignalChange "$show = !$show" ] []
374+
Elem.div [ Ds.onSignalPatch "$show = !$show" ] []
375+
376+
Elem.div [ Ds.onSignalPatchFilter (SignalsFilter.Include "/foo/") ] []
376377
```
377378

378379
### [Ds.onInterval : `data-on-interval`](https://data-star.dev/reference/attributes#data-on-interval)
@@ -407,7 +408,7 @@ All signals, that do not have an underscore prefix, are sent in the request.
407408
`@get` will send the signal values as query parameters. All others are sent within a JSON body.
408409

409410
```fsharp
410-
Elem.div [ Ds.onLoad (Ds.get "/get") ] []
411+
Elem.div [ Ds.init (Ds.get "/get") ] []
411412
412413
Elem.button [ Ds.onClick (Ds.post "/post") ] [ Text.raw "Post" ]
413414
@@ -450,21 +451,21 @@ Toggles all the signals that start with the prefix. This is useful for toggling
450451
Elem.div [ Ds.onEvent (OnEvent.SignalsChanged, (Ds.toggleAll "foo.")) ] []
451452
```
452453

453-
### [Ds.ignore | Ds.ignoreThis | Ds.ignoreMorph : `data-star-ignore`](https://data-star.dev/reference/attributes#data-star-ignore)
454+
### [Ds.ignore | Ds.ignoreSelf | Ds.ignoreMorph : `data-star-ignore`](https://data-star.dev/reference/attributes#data-ignore)
454455

455456
Datastar walks the entire DOM and applies plugins to each element it encounters.
456457
It’s possible to tell Datastar to ignore an element and its descendants by placing a data-star-ignore attribute on it.
457458
This can be useful for preventing naming conflicts with third-party libraries.
458459

459460
`Ds.ignore` will force Datastar to ignore the element and all child elements.
460-
`Ds.ignoreThis` only affects the attribute it is attached to.
461+
`Ds.ignoreSelf` only affects the attribute it is attached to.
461462

462463
```fsharp
463464
Elem.div [ Ds.ignore ] [
464465
Elem.div [ Ds.text "ignoredAsWell" ] []
465466
]
466467
467-
Elem.div [ Ds.ignoreThis ] [
468+
Elem.div [ Ds.ignoreSelf ] [
468469
Elem.div [ Ds.text "thisIsNotIgnored" ] []
469470
]
470471
@@ -487,7 +488,7 @@ Elem.pre [ Ds.jsonSignalsOptions (SignalsFilter.Include "/foo/") ] []
487488
## _When to `$`_
488489

489490
You may have noticed in the sample code that the `$` is used in some places, but not others. At first, it might be
490-
confusing when a `$` is required, but it really isn't all that complicated when you think of it as either being a signal path or an expression.
491+
confusing when a `$` is required, but it really isn't all that complicated when you think of it as either being a signal path or not.
491492

492493
The `$` symbol is a shorthand to get the value of the signal (e.g. `$count` -> `count.value`), so when the `$` is elided, you are referring to the signal directly.
493494
[`Ds.bind signalPath`](#dsbind--data-bind) is two-way binding to the signal, so it requires the signal path, no `$`.
@@ -627,15 +628,16 @@ are mirrored with a function with `sse` as their prefix instead of `of`.
627628

628629
```fsharp
629630
let handleStream = (fun ctx -> task {
630-
do! Response.sseStartResponse ctx
631+
do! Response.sseStartResponse ctx // make sure this is called first; sends the appropriate headers
631632
632633
let mutable counter = 0
633634
634-
while true do // all Datastar methods (unless requested otherwise) will throw on ctx.RequestAborted
635+
while true do // all Datastar methods will throw on ctx.RequestAborted
635636
do! Response.ssePatchSignal ctx (sp"counter") counter
636637
do! Response.sseHtmlElements ctx ( Elem.pre [ Attr.id "counterId" ] [ Text.raw counter.ToString() ] )
637638
do! Task.Delay(TimeSpan.FromSeconds 1L, ctx.RequestAborted)
638639
counter <- counter + 1
640+
})
639641
```
640642

641643
See the [Streaming example](examples/Streaming) for more.

examples/ClickToEdit/ClickToEdit.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let ofMainBody : HttpHandler =
1616
]
1717
Elem.body [] [
1818
Text.h1 "Example: Click to Edit"
19-
Elem.div [ Attr.id "contact"; Ds.onLoad (Ds.get "clickToEdit/view") ] []
19+
Elem.div [ Attr.id "contact"; Ds.onInit (Ds.get "clickToEdit/view") ] []
2020
]
2121
]
2222
Response.ofHtml htmlXml

examples/ClickToLoad/ClickToLoad.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let handleIndex: HttpHandler =
3535
[ Elem.th [] [ Text.raw "Name" ]
3636
Elem.th [] [ Text.raw "Email" ]
3737
Elem.th [] [ Text.raw "ID" ] ]
38-
Elem.tbody [ Attr.id "agent_rows"; Ds.onLoad (Ds.get "/moreAgents") ] [] ] ] ]
38+
Elem.tbody [ Attr.id "agent_rows"; Ds.onInit (Ds.get "/moreAgents") ] [] ] ] ]
3939

4040
Response.ofHtml html
4141

examples/Signals/Signals.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let handleIndex : HttpHandler =
125125
Elem.label [ Attr.for' "r6" ] [ Text.raw "Six" ]
126126
Elem.br [
127127
// note that this must follow AFTER the refs are created above
128-
Ds.filterOnSignalPatch (sf"^checkBoxSignal$")
128+
Ds.onSignalPatchFilter (sf"^checkBoxSignal$")
129129
Ds.onSignalPatch "$r4.name = $r5.name = $r6.name = ($checkBoxSignal ? 'radioGroup2' : 'radioGroup1')"
130130
]
131131
]

examples/Streaming/Streaming.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ let handleIndex ctx = task {
4141
Elem.body [
4242
Ds.signal (SignalPath.userName, user)
4343
Ds.signal (SignalPath.displayType, UserState.displayBadApple)
44-
Ds.filterOnSignalPatch (SignalsFilter.Include SignalPath.displayType)
44+
Ds.onSignalPatchFilter (SignalsFilter.Include SignalPath.displayType)
4545
Ds.onSignalPatch (Ds.get "/channel")
4646
Ds.safariStreamingFix
4747
] [
48-
Elem.div [ Ds.onLoad (Ds.get "/stream") ] []
48+
Elem.div [ Ds.onInit (Ds.get "/stream") ] []
4949

5050
Text.h1 "Example: Streaming"
5151

src/Falco.Datastar/Ds.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ open StarFederation.Datastar.FSharp
1010
[<AbstractClass; Sealed; RequireQualifiedAccess>]
1111
type Ds =
1212
static member cdnSrc =
13-
@"https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.0-RC.5/bundles/datastar.js"
13+
@"https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.0-RC.6/bundles/datastar.js"
1414

1515
/// <summary>
1616
/// Shorthand for `Elem.script [ Attr.type' "module"; Attr.src cdnSrc ] []`
@@ -120,7 +120,7 @@ type Ds =
120120

121121
/// <summary>
122122
/// Create a signal that refers to the HTML element it is assigned to; after a data-ref is created, you can access attributes of the element.
123-
/// e.g. data-on-click="$signalRefName.value='newValue'".
123+
/// e.g. data-on:click="$signalRefName.value='newValue'".
124124
/// Note: that if an element's attribute changes, the expressions containing this signal will not fire.
125125
/// https://data-star.dev/reference/attributes#data-ref
126126
/// </summary>
@@ -188,7 +188,7 @@ type Ds =
188188
/// https://data-star.dev/reference/attributes#data-ignore
189189
/// </summary>
190190
/// <returns>Attribute</returns>
191-
static member ignoreThis =
191+
static member ignoreSelf =
192192
DsAttr.start "ignore"
193193
|> DsAttr.addModifier { Name="self"; Tags = [] }
194194
|> DsAttr.create
@@ -253,14 +253,14 @@ type Ds =
253253

254254
/// <summary>
255255
/// Fires the expression when the element is loaded.
256-
/// https://data-star.dev/reference/attributes#data-on-load
256+
/// https://data-star.dev/reference/attributes#data-init
257257
/// </summary>
258258
/// <param name="expression">The expression to evaluate when the event is triggered; https://data-star.dev/guide/datastar_expressions</param>
259259
/// <param name="delayMs">The time to wait before executing the expression in milliseconds; default = 0</param>
260260
/// <param name="viewTransition">Wrap expression in document.startViewTransition(); default = false</param>
261261
/// <returns>Attribute</returns>
262-
static member onLoad (expression, ?delayMs, ?viewTransition) =
263-
DsAttr.start "on-load"
262+
static member onInit (expression, ?delayMs, ?viewTransition) =
263+
DsAttr.start "init"
264264
|> DsAttr.addModifierOption (delayMs |> Option.map DsAttrModifier.DelayMs)
265265
|> DsAttr.addModifierNameIf "viewtransition" (defaultArg viewTransition false)
266266
|> DsAttr.addValue expression
@@ -283,7 +283,7 @@ type Ds =
283283

284284
/// <summary>
285285
/// Fires the expression when a signal is changed. Filter using Ds.filterOnSignalPatch
286-
/// hhttps://data-star.dev/reference/attributes#data-on-signal-patch
286+
/// https://data-star.dev/reference/attributes#data-on-signal-patch
287287
/// </summary>
288288
/// <param name="expression">The expression to evaluate when the event is triggered; https://data-star.dev/guide/datastar_expressions</param>
289289
/// <param name="delayMs">The time to wait before executing the expression in milliseconds; default = 0</param>
@@ -304,7 +304,7 @@ type Ds =
304304
/// </summary>
305305
/// <param name="signalsFilter">Regex of signal paths to be included and excluded</param>
306306
/// <returns>Attribute</returns>
307-
static member filterOnSignalPatch (signalsFilter:SignalsFilter) =
307+
static member onSignalPatchFilter (signalsFilter:SignalsFilter) =
308308
DsAttr.start "on-signal-patch-filter"
309309
|> DsAttr.addValue (signalsFilter |> SignalsFilter.serialize)
310310
|> DsAttr.create
@@ -437,4 +437,4 @@ type Ds =
437437
/// https://stackoverflow.com/questions/8788802/prevent-safari-loading-from-cache-when-back-button-is-clicked
438438
/// </summary>
439439
static member safariStreamingFix =
440-
Attr.create "data-on-pageshow.window" "evt?.persisted && window.location.reload()"
440+
Attr.create "data-on:pageshow.window" "evt?.persisted && window.location.reload()"

src/Falco.Datastar/Falco.Datastar.fsproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AssemblyName>Falco.Datastar</AssemblyName>
4-
<Version>1.0.0</Version>
4+
<Version>1.1.0</Version>
55

66
<!-- General info -->
77
<Description>Datastar Bindings for the Falco web toolkit.</Description>
@@ -19,7 +19,7 @@
1919

2020
<!-- NuGet config -->
2121
<PackageId>Falco.Datastar</PackageId>
22-
<PackageVersion>1.0.0</PackageVersion>
22+
<PackageVersion>1.1.0</PackageVersion>
2323
<PackageTags>fsharp;web;falco;falco-sharp;data-star</PackageTags>
2424
<PackageProjectUrl>https://github.com/falcoframework/Falco.Datastar</PackageProjectUrl>
2525
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
@@ -33,6 +33,7 @@
3333
<PublishRepositoryUrl>true</PublishRepositoryUrl>
3434
<EmbedUntrackedSources>true</EmbedUntrackedSources>
3535
<IncludeSymbols>true</IncludeSymbols>
36+
<Title>Falco.Datastar</Title>
3637
</PropertyGroup>
3738

3839
<ItemGroup>

0 commit comments

Comments
 (0)