Got it, thanks much to you both. Still getting used to F#, didn't think about (or notice) the top-level value vs. a function thing.

By on 11/16/2015 9:12 AM ()

WebSharper 3 does not follow .NET semantics of F# here, top level values are always evaluated on page load. While in .NET, all top level values of a single file are evaluated when any of them are accessed first (there are classes with static constructors generated for this).

By on 11/16/2015 9:24 AM ()

How is the index.html file chosen, and more importantly, recognized as dependant on Client.Main()?

By on 11/16/2015 8:21 AM ()

It's just served because it's the default file chosen by the ASP.NET server when there is no handler for /. It is not recognized as dependant on anything, it just includes the script files generated by WebSharper. The reason why Client.Main is run is that it's a top-level value, rather than a function: it is defined as let Main = ... and not let Main() = ..., so the definition is run on startup. If you add other similar top-level value definitions in your code, then they will be run too.

By on 11/16/2015 8:34 AM ()

This is an SPA, index.html is assumed to be "the page", and it gets all the necessary references when you create the project (e.g. to the generated .head.js containing the inner dependencies, and to the main JS file generated from Client.fs, etc.)

Since the code from Client.fs is "wired in", it needs to act accordingly - so if it has only functions, nothing much will happen, but if you add at least one top-level binding in it (such as Main in the template) and make that "have a side-effect" (such as Doc.RunById), it will serve as the main entrypoint to your app.

By on 11/16/2015 8:28 AM ()

The key is the |> Doc.RunById "main" line, which inserts the UI.Next Doc value to the "main" placeholder in the corresponding index.html file.

By on 11/16/2015 8:14 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper