/// <summary> /// Set up three calculator model objects for each calculator view /// Explicitly set to null to enforce loading needed (unlike in F#) /// </summary> public static WebSharper.UI.Doc MainDoc(Var <string> page) { var varViewStateCalculator = Var.Create(new CalculatorViewModel()); varViewStateCalculator.Set(null); var viewViewStateCalculator = varViewStateCalculator.View.MapAsync <CalculatorViewModel, CalculatorViewModel>(c => { if (c == null) { return(CalculatorServer.Load(SessionStorage.ViewState)); } else { return(Task.FromResult(c)); } }); var varSessionCalculator = Var.Create(new CalculatorViewModel()); varSessionCalculator.Set(null); var viewSessionCalculator = varSessionCalculator.View.MapAsync <CalculatorViewModel, CalculatorViewModel>(c => { if (c == null) { return(CalculatorServer.Load(SessionStorage.Session)); } else { return(Task.FromResult(c)); } }); var varDatabaseCalculator = Var.Create(new CalculatorViewModel()); varDatabaseCalculator.Set(null); var viewDatabaseCalculator = varDatabaseCalculator.View.MapAsync <CalculatorViewModel, CalculatorViewModel>(c => { if (c == null) { return(CalculatorServer.Load(SessionStorage.Database)); } else { return(Task.FromResult(c)); } }); return(new Template.Triptych.Main() .ViewState(CalculatorDoc.MainDoc(viewViewStateCalculator, varViewStateCalculator, page, id: ViewStateDoc)) .Session(CalculatorDoc.MainDoc(viewSessionCalculator, varSessionCalculator, page, id: SessionDoc)) .Database(CalculatorDoc.MainDoc(viewDatabaseCalculator, varDatabaseCalculator, page, id: DatabaseDoc)) .Doc()); }
public static object Page(Var <string> page, View <CalculatorViewModel> viewCalculator, Var <CalculatorViewModel> varCalculator) => V(page.V).Map(showPage => { switch (showPage) { case Single: varCalculator.Set(null); // enforce reload after storage change return(CalculatorDoc.MainDoc(viewCalculator, varCalculator, page)); case Triptych: return(TriptychDoc.MainDoc(page)); default: throw new Exception(string.Format( // JS: no NotImplementedException "Page {0}", showPage)); } });