public static void Main() { var people = ListModel.FromSeq(new[] { "John", "Paul" }); var newName = Var.Create(""); var router = InferRouter.Router.Infer <Home>(); var endpoint = router.InstallHash(new Home()); var routed = endpoint.View.Map((Home act) => { switch (act) { case Home.Person p: return(div(p.Name.First, " ", p.Name.Last, p.Age == null ? " won't tell their age!" : $" is {p.Age} years old!", button("Back", () => endpoint.Value = new Home()) )); case Home.People p: return(ul(p.people.Select(x => li(x.First, " ", x.Last)).ToArray())); default: var first = Var.Create("John"); var last = Var.Create("Doe"); var age = Var.Create(20); return(div( input(first), input(last), input(age), button("Go", () => endpoint.Value = new Home.Person(new Name(first.Value, last.Value), age.Value == 0 ? null : (int?)age.Value)) )); } }); div( h1("My list of unique people"), ul(people.View.DocSeqCached((string x) => li(x))), div( input(newName, attr.placeholder("Name")), button("Add", () => { people.Add(newName.Value); newName.Value = ""; }), div(newName.View) ), h1("Routed element:"), routed ).RunById("main"); TodoApp(); }
public static void Main() { var people = ListModel.FromSeq(new[] { "John", "Paul" }); var newName = Var.Create(""); var routed = new RouteMapBuilder() .With <Home>((go, _) => { var first = Var.Create("John"); var last = Var.Create("Doe"); var age = Var.Create(20); return(div( input(first), input(last), input(age), button("Go", () => go(new Person(new Name(first.Value, last.Value), age.Value == 0 ? null : (int?)age.Value))) )); }) .With <Person>((go, p) => div(p.Name.First, " ", p.Name.Last, p.Age == null ? " won't tell their age!" : $" is {p.Age} years old!", button("Back", () => go(new Home())) ) ) .With <People>((go, p) => ul(p.people.Select(x => li(x.First, " ", x.Last)).ToArray()) ) .Install(); div( h1("My list of unique people"), ul(people.View.DocSeqCached((string x) => li(x))), div( input(newName, attr.placeholder("Name")), button("Add", () => { people.Add(newName.Value); newName.Value = ""; }), div(newName.View) ), h1("Routed element:"), routed ).RunById("main"); }
public static void ClientMain() { var people = ListModel.FromSeq(new[] { "John", "Paul" }); var newName = Var.Create(""); new Template.Index.Main() .ListContainer( people.View.DocSeqCached((string x) => new Template.Index.ListItem().Name(x).Doc() ) ) .Name(newName) .Add(() => { people.Add(newName.Value); newName.Value = ""; }) .Doc() .RunById("main"); }