get it to run

This commit is contained in:
caleb 2025-07-08 21:22:14 +09:00
parent b1afd45d41
commit bd3a93d628
4 changed files with 14 additions and 34 deletions

View File

@ -15,6 +15,9 @@ fsharp_space_before_uppercase_invocation = true
[*.{fs,fsx,fsi}] [*.{fs,fsx,fsi}]
fsharp_bar_before_discriminated_union_declaration = true fsharp_bar_before_discriminated_union_declaration = true
max_line_length = 120 max_line_length = 120
fsharp_array_or_list_multiline_formatter = number_of_items
fsharp_max_array_or_list_number_of_items = 4
fsharp_max_function_binding_width=0
# C# files # C# files
[*.cs] [*.cs]

View File

@ -4,27 +4,14 @@ open WebSharper
open WebSharper.JavaScript open WebSharper.JavaScript
open WebSharper.UI open WebSharper.UI
open WebSharper.UI.Client open WebSharper.UI.Client
open WebSharper.UI.Html
open WebSharper.UI.Templating open WebSharper.UI.Templating
[<JavaScript>] [<JavaScript>]
module Client = module Client =
// The templates are loaded from the DOM, so you just can edit index.html
// and refresh your browser, no need to recompile unless you add or remove holes.
type IndexTemplate = Template<"wwwroot/index.html", ClientLoad.FromDocument>
let People = ListModel.FromSeq [ "John"; "Paul" ]
[<SPAEntryPoint>] [<SPAEntryPoint>]
let Main () = let Main () =
let newName = Var.Create "" div [] [
p [] [ text "hello world" ]
IndexTemplate ]
.Main()
.ListContainer(People.View.DocSeqCached (fun (name: string) -> IndexTemplate.ListItem().Name(name).Doc ()))
.Name(newName)
.Add(fun _ ->
People.Add newName.Value
newName.Value <- "")
.Doc ()
|> Doc.RunById "main" |> Doc.RunById "main"

View File

@ -8,10 +8,13 @@ open web_api_cookbook
[<EntryPoint>] [<EntryPoint>]
let main args = let main args =
let builder = WebApplication.CreateBuilder (args) let builder = WebApplication.CreateBuilder args
// Add services to the container. // Add services to the container.
builder.Services.AddWebSharper().AddAuthentication("WebSharper").AddCookie ("WebSharper", fun options -> ()) builder.Services
.AddWebSharper()
.AddAuthentication("WebSharper")
.AddCookie ("WebSharper", fun options -> ())
|> ignore |> ignore
let app = builder.Build () let app = builder.Build ()
@ -27,7 +30,7 @@ let main args =
app app
.UseHttpsRedirection() .UseHttpsRedirection()
#if DEBUG #if DEBUG
.UseWebSharperScriptRedirect(startVite = true) // .UseWebSharperScriptRedirect(startVite = true)
#endif #endif
.UseDefaultFiles() .UseDefaultFiles()
.UseStaticFiles() .UseStaticFiles()

View File

@ -5,23 +5,10 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="Scripts/web_api_cookbook.css" /> <link rel="stylesheet" type="text/css" href="Scripts/web_api_cookbook.css" />
<style>
/* Don't show the not-yet-loaded templates */
[ws-template], [ws-children-template] { display: none; }
</style>
<script type="text/javascript" src="Scripts/web_api_cookbook.head.js"></script> <script type="text/javascript" src="Scripts/web_api_cookbook.head.js"></script>
</head> </head>
<body> <body>
<h1>My list of unique people</h1> <div id="main">
<div id="main" ws-children-template="Main">
<ul ws-hole="ListContainer">
<li ws-template="ListItem">${Name}</li>
</ul>
<div>
<input ws-var="Name" placeholder="Name" />
<button ws-onclick="Add">Add</button>
<div>You are about to add: ${Name}</div>
</div>
</div> </div>
<script type="module" src="Scripts/web_api_cookbook.min.js"></script> <script type="module" src="Scripts/web_api_cookbook.min.js"></script>
</body> </body>