<input value=”$Name” />
[Unit] public class Page { Name : string = "world"; [Html] public View() : string { <# <input value=”$Name” /> <div>Hello, $Name</div> #> } }
public ActionResult PageWithModel() { return View("Index", (object)NemerleProject.MyModel.Render()); }
// [Unit] JavaScript, // Server, // ASP.NET MVC Controller [Unit] public class ReactiveToDo { // [Dto] public mutable. // [Record], , // [Dto] public class Task { Name : string; IsDone : bool; Priority : string; } // [Unit] Server, . // Nemerle C#. // , mutable. mutable _tasks = List.[Task](); mutable _todoName = "New task"; mutable _todoPriority = "high"; public this() { // server , Unit // Server (. ) // Load() callback, // . // Load , callback - . // XMLHttpRequest // . _ = server.Load(tasks => SetTasks(tasks)); } // SignalR, // SetTasks(tasks : List[Task]) : void { _tasks = tasks; } Add() : void { _tasks.Add(Task(_todoName, false, _todoPriority)); SaveToServer(); _todoName = "Task #" + _tasks.Count; _todoPriority = "high"; } SaveToServer() : void { // Save List[Task], // . // , // , // window.console.log JavaScript . _ = server.Save(_tasks, status => window.console.log(status)) } // . // , LINQ, // linq.js // <# #> - C# @””, . // : <# <# a #> #> . [Html] public View() : string { <# <table class="reactive-todo-table"> <tr> <th>Priority</th><th>Task</th><th>Status</th> </tr> <tr $foreach(task in _tasks.OrderBy(t => t.Priority))> <td>$(task.Priority)</td> <td>$(task.Name)</td> <td><input type="checkbox" event-change="$SaveToServer" checked="$(task.IsDone)" /></td> </tr> </table> <div> <input value="$_todoName" /> <select value="$_todoPriority"> <option>high</option> <option>low</option> </select> <button click="$Add">Add</button> </div> #> } // ASP.NET MVC // , // , // . // [SignalR] Server, // broadcast signal (. ) [SignalR] public class Server { // . // . static mutable _db : List[Task] = List(); static this() { _db.Add(Task("Write article", false, "high")); _db.Add(Task("Fix website bugs", false, "high")); _db.Add(Task("Add new functionality", false, "low")); } public Load() : List[Task] { // Nemerle return // " " _db } // . // 'void'. public Save(tasks : List[Task]) : string { _db = tasks; // SignalR. , // . // client, // . // . // broadcast SetTasks . // signal, // broadcast client.SetTasks(_db); // , : "ok" } } }
Source: https://habr.com/ru/post/239421/
All Articles