Created
October 7, 2014 07:14
-
-
Save ionoy/1424ef755d04cec34284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
public class ReactiveToDo | |
{ | |
[Dto] public class Task { Name : string; IsDone : bool; Priority : string; } | |
mutable _tasks = List.[Task](); | |
mutable _todoName = "New task"; | |
mutable _todoPriority = "high"; | |
public this() | |
{ | |
_ = server.Load(tasks => SetTasks(tasks)); | |
} | |
SetTasks(tasks : List[Task]) : void | |
{ | |
_tasks = tasks; | |
} | |
Add() : void | |
{ | |
_tasks.Add(Task(_todoName, false, _todoPriority)); | |
SaveToServer(); | |
_todoName = "Task #" + _tasks.Count; | |
_todoPriority = "high"; | |
} | |
SaveToServer() : void | |
{ | |
_ = server.Save(_tasks, status => window.console.log(status)) | |
} | |
[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> | |
#> | |
} | |
[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] | |
{ | |
_db | |
} | |
public Save(tasks : List[Task]) : string | |
{ | |
_db = tasks; | |
broadcast client.SetTasks(_db); | |
"ok" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Сделайте аналогичный пример на других средствах, чтобы было видно насколько ваша реализация короче, проще и нагляднее.