Skip to content

Commit 09dc487

Browse files
authored
Merge pull request #14 from falcoframework/bugfix/action_content_type
bugfix/action_content_type
2 parents 08a4aaf + a05d042 commit 09dc487

14 files changed

Lines changed: 275 additions & 82 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
dotnet-version: ['9.0.x']
13+
dotnet-version: ['10.0.x']
1414
steps:
1515
- uses: actions/checkout@v2
1616

Falco.Datastar.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Streaming", "Examples\Strea
1818
EndProject
1919
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Falco.Datastar.Tests", "test\Falco.Datastar.Tests\Falco.Datastar.Tests.fsproj", "{772A0FC5-A796-4408-9751-53842F8B8C77}"
2020
EndProject
21+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "InputForm", "examples\InputForm\InputForm.fsproj", "{19E053A0-6EA6-4818-AF0D-5BE0B36D55EF}"
22+
EndProject
23+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "environment", "environment", "{13C18205-082E-4DED-9AD4-D3001ABDFECA}"
24+
ProjectSection(SolutionItems) = preProject
25+
global.json = global.json
26+
.github\workflows\build.yml = .github\workflows\build.yml
27+
EndProjectSection
28+
EndProject
2129
Global
2230
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2331
Debug|Any CPU = Debug|Any CPU
@@ -30,6 +38,7 @@ Global
3038
{8E2C0AA3-07E5-40D8-8F16-905F5F1D30AE} = {305B55B6-83D0-453C-A77E-080214FA0657}
3139
{0187E584-68DF-4D8C-874C-FF8E061932DF} = {305B55B6-83D0-453C-A77E-080214FA0657}
3240
{AECB950B-20DD-40C4-9ACA-3A8FF1CFBC05} = {305B55B6-83D0-453C-A77E-080214FA0657}
41+
{19E053A0-6EA6-4818-AF0D-5BE0B36D55EF} = {305B55B6-83D0-453C-A77E-080214FA0657}
3342
EndGlobalSection
3443
GlobalSection(ProjectConfigurationPlatforms) = postSolution
3544
{6BCE09E2-DA8E-44F9-B5EC-C4F76E329471}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -64,5 +73,9 @@ Global
6473
{772A0FC5-A796-4408-9751-53842F8B8C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
6574
{772A0FC5-A796-4408-9751-53842F8B8C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
6675
{772A0FC5-A796-4408-9751-53842F8B8C77}.Release|Any CPU.Build.0 = Release|Any CPU
76+
{19E053A0-6EA6-4818-AF0D-5BE0B36D55EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77+
{19E053A0-6EA6-4818-AF0D-5BE0B36D55EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{19E053A0-6EA6-4818-AF0D-5BE0B36D55EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
79+
{19E053A0-6EA6-4818-AF0D-5BE0B36D55EF}.Release|Any CPU.Build.0 = Release|Any CPU
6780
EndGlobalSection
6881
EndGlobal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Some important notes: Signals defined later in the DOM tree override those defin
152152
## _Creating Signals_
153153

154154
Create signals, which are reactive variables that automatically propagate their value to all references of the signal.
155+
Important: Never use hyphens when naming signals.
155156

156157
### [Ds.signals / Ds.signal : `data-signals`](https://data-star.dev/reference/attributes#data-signals)
157158

@@ -428,7 +429,6 @@ Each request action can also be provided a number of options, explained in depth
428429
```fsharp
429430
Elem.button [ Ds.onClick (Ds.get ("/endpoint",
430431
{ RequestOptions.Defaults with
431-
IncludeLocal = true;
432432
Headers = [ ("X-Csrf-Token", "JImikTbsoCYQ9...") ]
433433
OpenWhenHidden = true }
434434
)) ] [ Text.raw "Push the Button" ]

examples/InputForm/InputForm.fs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
open Falco
2+
open Falco.Datastar.Selector
3+
open Falco.Datastar.SignalPath
4+
open Falco.Markup
5+
open Falco.Routing
6+
open Falco.Datastar
7+
open Microsoft.AspNetCore.Builder
8+
open Microsoft.AspNetCore.Http
9+
10+
module View =
11+
let template content =
12+
Elem.html [ Attr.lang "en" ] [
13+
Elem.head [] [ Ds.cdnScript ]
14+
Elem.body [] content
15+
]
16+
17+
module App =
18+
let handleIndex : HttpHandler =
19+
let checkbox name =
20+
[ Text.raw $"{name}:"; Elem.input [ Attr.type' "checkbox"; Attr.name "checkboxes"; Attr.value name ] ]
21+
let html =
22+
View.template [
23+
Text.h1 "Example: Input Form"
24+
Elem.div [] [
25+
Elem.form [ Attr.id "myform" ] [
26+
yield! checkbox "foo"
27+
yield! checkbox "bar"
28+
yield! checkbox "baz"
29+
Elem.button [ Ds.onClick (Ds.get("/endpoint1", RequestOptions.With(Form))) ] [ Text.raw "Submit GET Request" ]
30+
Elem.button [ Ds.onClick (Ds.post("/endpoint1", RequestOptions.With(Form))) ] [ Text.raw "Submit POST Request" ]
31+
]
32+
Elem.button [ Ds.onClick (Ds.get("/endpoint1", RequestOptions.With(SelectedForm (sel"#myform")))) ] [
33+
Text.raw "Submit GET request from outside the form"
34+
]
35+
]
36+
Elem.hr []
37+
Elem.div [] [
38+
Elem.form [ Ds.onEvent ("submit", (Ds.post ("/endpoint2", RequestOptions.With(Form)))) ] [
39+
Text.raw "foo:"
40+
Elem.input [ Attr.type' "text"; Attr.name "foo"; Attr.required ]
41+
Elem.button [] [ Text.raw "Submit Form" ]
42+
]
43+
]
44+
]
45+
Response.ofHtml html
46+
47+
let handleEndpointOne (getForm:HttpContext -> RequestData) : HttpHandler = (fun ctx -> task {
48+
let method = ctx.Request.Method
49+
let form = ctx |> getForm
50+
let foo = form.GetStringList("checkboxes")
51+
52+
let alertString = $"Form data received via {method} request: checkboxes = {foo}"
53+
let alertScript = $"alert('{alertString}')"
54+
55+
return Response.ofExecuteScript alertScript ctx
56+
})
57+
58+
let handleEndpointTwo (getForm:HttpContext -> RequestData): HttpHandler = (fun ctx -> task {
59+
let method = ctx.Request.Method
60+
let form = ctx |> getForm
61+
let foo = form.GetString("foo")
62+
63+
let alertString = $"Form data received via {method} request: foo = {foo}"
64+
let alertScript = $"alert('{alertString}')"
65+
66+
return Response.ofExecuteScript alertScript ctx
67+
})
68+
69+
70+
[<EntryPoint>]
71+
let main args =
72+
let wapp = WebApplication.Create()
73+
74+
let endpoints =
75+
[
76+
get "/" App.handleIndex
77+
all "/endpoint1" [
78+
GET, (App.handleEndpointOne Request.getQuery)
79+
POST, (App.handleEndpointOne (fun ctx -> (ctx |> Request.getForm).Result))
80+
]
81+
all "/endpoint2" [
82+
GET, (App.handleEndpointTwo Request.getQuery)
83+
POST, (App.handleEndpointTwo (fun ctx -> (ctx |> Request.getForm).Result))
84+
]
85+
]
86+
87+
wapp.UseRouting()
88+
.UseFalco(endpoints)
89+
.Run()
90+
0 // Exit code
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="InputForm.fs" />
7+
</ItemGroup>
8+
<ItemGroup>
9+
<PackageReference Include="Falco" Version="5.0.0" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\src\Falco.Datastar\Falco.Datastar.fsproj" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<Content Update="wwwroot\style.css">
16+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17+
</Content>
18+
</ItemGroup>
19+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Urls": "http://localhost:5001",
3+
"Logging": {
4+
"LogLevel": {
5+
"Default": "Information"
6+
}
7+
}
8+
}

examples/Streaming/Animation.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let private totalBadAppleFrames = badAppleFrames |> Array.length
4040
backgroundTask {
4141
while true do
4242
currentBadAppleFrame <- (currentBadAppleFrame + 1) % totalBadAppleFrames
43-
do! Task.Delay(TimeSpan.FromMilliseconds(50))
43+
do! Task.Delay(TimeSpan.FromMilliseconds(50L))
4444
} |> ignore
4545

4646
let getCurrentBadAppleFrame () = badAppleFrames[currentBadAppleFrame]

examples/Streaming/Streaming.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let handleIndex ctx = task {
3636
Elem.html [] [
3737
Elem.head [ Attr.title "Streaming" ] [
3838
Ds.cdnScript
39-
Elem.script [ Attr.type' "module"; Attr.src "datastar-inspector.js" ] []
39+
Elem.script [ Attr.type' "module" ] []
4040
]
4141
Elem.body [
4242
Ds.signal (SignalPath.userName, user)
@@ -62,8 +62,6 @@ let handleIndex ctx = task {
6262
Elem.label [ Attr.for' "streamDisplayGuids" ] [ Text.raw "Viewers" ]
6363

6464
Elem.div [ Attr.id ElementIds.streamView ] []
65-
66-
Elem.create "datastar-inspector" [] []
6765
]
6866
]
6967
return Response.ofHtml (html (Guid.NewGuid())) ctx
@@ -110,7 +108,7 @@ let handleStream ctx = task {
110108
]
111109

112110
do! Response.sseHtmlElements ctx patch
113-
do! Task.Delay (TimeSpan.FromSeconds(10L), ctx.RequestAborted)
111+
do! Task.Delay (TimeSpan.FromMilliseconds(50), ctx.RequestAborted)
114112
finally
115113
userDisplays.AddOrUpdate (signalUser, UserState.displayBadApple, Func<User, UserState, UserState>(fun _ _ -> UserState.loggedOff)) |> ignore
116114
return ()

global.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": {
3+
"version": "10.0.0",
4+
"rollForward": "latestFeature",
5+
"allowPrerelease": false
6+
}
7+
}

0 commit comments

Comments
 (0)