public void FuncInterop() { Equal( Microsoft.FSharp.Collections.ArrayModule.Map <int, string>(FSharpConvert.Fun((int i) => i.ToString()), new[] { 1, 2 }), new[] { "1", "2" } ); }
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); }
public void Option() { IsTrue(FSharpOption <int> .get_IsNone(FSharpOption <int> .None)); Equal(FSharpOption <int> .None, null); Equal(FSharpOption <int> .GetTag(FSharpOption <int> .None), 0); Equal(FSharpOption <int> .GetTag(FSharpOption <int> .Some(2)), 1); Equal(FSharpOption <int> .Some(3).Value, 3); Equal(FSharpOption <int> .Some(1), FSharpConvert.Some(1)); Equal(FSharpConvert.Option((int?)1), FSharpOption <int> .Some(1)); }
public void FSharpRef() { var x = FSharpConvert.Ref <int>(); Equal(x.contents, 0); Equal(x.Value, 0); x.Value++; Equal(x.Value, 1); var y = FSharpConvert.Ref <int>(5); Equal(y.Value, 5); }
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); }
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"); }
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"); }
public void ImplicitConversions() { FSharpOption <int> o = 3; Equal(o, FSharpConvert.Some(3)); }
public int AddWithFSharpFunc(int y, int z) => I.Module.InvokeFunc2(FSharpConvert.Fun <int, int, int>(Add), y, z);
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); }
public Main Add(Action x) { holes.Add(TemplateHole.NewEvent("add", FSharpConvert.Fun <DomElement, DomEvent>((a, b) => x()))); return(this); }