Skip to content

Instantly share code, notes, and snippets.

@ionoy
Created October 7, 2014 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionoy/1424ef755d04cec34284 to your computer and use it in GitHub Desktop.
Save ionoy/1424ef755d04cec34284 to your computer and use it in GitHub Desktop.
[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"
}
}
}
@VladD2
Copy link

VladD2 commented Oct 8, 2014

Сделайте аналогичный пример на других средствах, чтобы было видно насколько ваша реализация короче, проще и нагляднее.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment