Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        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");
        }