c4fsharp / c4fsharp.github.io

Community for F# website
http://c4fsharp.github.io/
6 stars 2 forks source link

Switch to WebSharper #13

Closed panesofglass closed 9 years ago

panesofglass commented 10 years ago

See WebSharper.UI.Next samples. This should allow us to build a simple single page app that could load and render markdown files as navigable HTML fragments.

t0yv0 commented 10 years ago

For something little here, can use whatever works.

For clarity sake, how would an ideal router interface look like in F#/WebSharper? The Director one seems to be interesting but does it do the reverse (linking?).

If I had to design one right now, I would go for something like this:


/// Framework gives this little type that defines `'T -> Url` and `Url -> option<'T>`.
/// Contract on the type is that these have to round-trip.
type Routes<'T>

val Link : Routes<'T> -> 'T -> Url
val TryRoute : Routes<'T> -> Url -> option<'T>

/// Various combinators for routes..

/// Now, main operation is installing some routes as current router: 
/// This is done once per application, and takes care of things like
/// history API and parsing current URL.
val Install : Routes<'T> -> Router<'T>

/// What can one do with a Router?
val Current : Router<'T> -> option<'T> // observe current route
val Changed : Router<'T> -> IEvent<'T> // observe when it changes
val Set : Router<'T> -> 'T -> unit // set current route, also pushes URL in History API

/// It is basically like a reactive variable we're thinking to introduce in W#.

/// Example usage:

type Action = | Home | About | Blog of id * int (* etc *)
let routes = Routes.Auto<Action>()
let router = Routes.Install routes
/// use router & routes in the application..
/// for example, can generate links `Routes.Link About routes`
/// can have content that depends on where we are by observing current route
/// can imperatively send the browser somewhere too - `Router.Set router Home`.