Exemplo n.º 1
0
 public void FuncInterop()
 {
     Equal(
         Microsoft.FSharp.Collections.ArrayModule.Map <int, string>(FSharpConvert.Fun((int i) => i.ToString()), new[] { 1, 2 }),
         new[] { "1", "2" }
         );
 }
Exemplo n.º 2
0
        public void FSharpFunc()
        {
            Equal(I.Module.ReturnsFunc().Invoke(3), 3);
            Equal(I.Module.ReturnsFunc2().Invoke(1).Invoke(2), 3);
            Func <int, int> f = I.Module.ReturnsFunc().Invoke;

            Equal(f(3), 3);
            Equal(I.Module.InvokeFunc(FSharpConvert.Fun((int x) => x + 1), 1), 2);
            Equal(I.Module.InvokeFunc2(FSharpConvert.Fun((int x, int y) => x + y), 1, 2), 3);
        }
Exemplo n.º 3
0
        public void FSharpFunc()
        {
            Equal(I.Module.ReturnsFunc().Invoke(3), 3);
            Equal(I.Module.ReturnsFunc2().Invoke(1).Invoke(2), 3);
            Func <int, int> f = I.Module.ReturnsFunc().Invoke;

            Equal(f(3), 3);
            Equal(I.Module.InvokeFunc(FSharpConvert.Fun((int x) => x + 1), 1), 2);
            Equal(I.Module.InvokeFunc2(FSharpConvert.Fun((int x, int y) => x + y), 1, 2), 3);
            Equal(I.Module.InvokeFunc(FuncConvert.FromFunc((int x) => x + 1), 1), 2);
            Equal(I.Module.InvokeFunc2(FuncConvert.FromFunc((int x, int y) => x + y), 1, 2), 3);
            Equal(I.Module.InvokeFunc(FuncConvert.ToFSharpFunc((int x) => x + 1), 1), 2);
            var c = FSharpFunc <int, int> .ToConverter(I.Module.ReturnsFunc());

            Equal(c(3), 3);
            var f2 = FSharpFunc <int, int> .FromConverter(c);

            Equal(f2.Invoke(3), 3);
        }
Exemplo n.º 4
0
        public static void ClientMain()
        {
            Model initialModel = Counter.Init();
            var   updateF      = FSharpConvert.Fun(Counter.UpdateFunc);
            var   renderF      = Counter.RenderFunc.FromRenderFunc();

            var remoteDevOptions = new RemoteDev.Options()
            {
                hostname = "localhost",
                port     = 8000
            };

            var app = WebSharper.Mvu.App.CreateSimple(initialModel, updateF, renderF);

            app = WebSharper.Mvu.App.WithRemoteDev(remoteDevOptions, app);
            Doc doc = WebSharper.Mvu.App.Run(app);

            doc.RunById("main");
        }
Exemplo n.º 5
0
        public static void TodoApp()
        {
            var Tasks =
                new ListModel <string, TaskItem>(task => task.Name)
            {
                new TaskItem("Have breakfast", 8, true),
                new TaskItem("Have lunch", 6, false)
            };
            var newTaskPriority = Var.Create(5);

            new Template.Template.Main()
            .ListContainer(
                Tasks.View
                .Map(l => (IEnumerable <TaskItem>)l.OrderByDescending(t => t.Priority))
                .DocSeqCached((TaskItem task) => new Template.Template.ListItem()
                              .Task(task.Name)
                              .Priority(task.Priority.ToString())
                              .Clear((el, ev) => Tasks.RemoveByKey(task.Name))
                              .Done(task.Done)
                              .ShowDone(attr.@class("checked", task.Done.View, x => x))
                              .Elt()
                              ))
            .Add((m) =>
            {
                Tasks.Add(new TaskItem(m.Vars.NewTaskName.Value, newTaskPriority.Value, false));
                m.Vars.NewTaskName.Value = "";
            })
            .ClearCompleted((el, ev) => Tasks.RemoveBy(task => task.Done.Value))
            .NewTaskPriority(newTaskPriority)
            .Doc()
            .RunById("tasks");
            new Template.Index.tasksTitle()
            .Elt()
            .OnAfterRender(FSharpConvert.Fun <JavaScript.Dom.Element>((el) => JavaScript.Console.Log("test")))
            .RunById("tasksTitle");
        }
Exemplo n.º 6
0
 public int AddWithFSharpFunc(int y, int z) => I.Module.InvokeFunc2(FSharpConvert.Fun <int, int, int>(Add), y, z);
Exemplo n.º 7
0
 public Main Add(Action <WebSharper.UI.Templating.Runtime.Server.TemplateEvent <Vars, WebSharper.JavaScript.Dom.MouseEvent> > x)
 {
     holes.Add(TemplateHole.NewEvent("add", FSharpConvert.Fun <DomElement, DomEvent>((a, b) => x(new WebSharper.UI.Templating.Runtime.Server.TemplateEvent <Vars, WebSharper.JavaScript.Dom.MouseEvent>(new Vars(instance), a, (WebSharper.JavaScript.Dom.MouseEvent)b))))); return(this);
 }
Exemplo n.º 8
0
 public Main Add(Action x)
 {
     holes.Add(TemplateHole.NewEvent("add", FSharpConvert.Fun <DomElement, DomEvent>((a, b) => x()))); return(this);
 }