F#
HTML
Result
Hosted on
Try WebSharper
<
>
namespace Samples open WebSharper open WebSharper.JavaScript open WebSharper.UI.Next open WebSharper.UI.Next.Html open WebSharper.UI.Next.Client open WebSharper.UI.Next.Notation [<JavaScript>] module SimpleInput = let counter = ref 0 let removedCounter = ref 0 let GetNextCounter() = incr counter; !counter type MessageType = Info | Warning | Error type Message = { Id: int Title: string Type: MessageType } let RandomMessage() = let id = GetNextCounter() { Id = id Title = sprintf "Message #%d" id Type = if id % 3 = 0 then Info elif id % 3 = 1 then Warning else Error } let Main = let messages = ListModel.Create (fun msg -> msg.Id) [RandomMessage()] div [ buttonAttr [ on.click (fun _ _ -> messages.Add(RandomMessage())) ] [text "Add"] buttonAttr [ on.click (fun _ _ -> if !removedCounter < !counter then incr removedCounter messages.RemoveByKey(!removedCounter) ) ] [text "Remove"] messages.View.DocSeqCached (fun msg -> let ty, bg = match msg.Type with | Info -> "info", "bg-success" | Warning -> "warning", "bg-warning" | Error -> "error", "bg-danger" pAttr [attr.``class`` bg] [text (ty + ": " + msg.Title)] ) ] |> Doc.RunById "main"
<html> <head> <title></title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> </head> <body> <div id="main"></div> <!--[BODY]--> </body> </html>