This commit is contained in:
Tony Garnock-Jones 2016-05-15 16:20:50 -04:00
parent 2b429b3fd9
commit d477e3d7dd
6 changed files with 1240 additions and 454 deletions

539
dist/syndicate.js vendored

File diff suppressed because one or more lines are too long

16
dist/syndicate.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

30
examples/table/index.html Normal file
View File

@ -0,0 +1,30 @@
<!doctype html>
<html>
<head>
<title>Syndicate: Table Example</title>
<meta charset="utf-8">
<script src="../../dist/syndicatecompiler.js"></script>
<script src="../../dist/syndicate.js"></script>
<script type="text/syndicate-js" src="index.js"></script>
</head>
<body>
<h1>Table Example</h1>
<table id="the-table">
<tbody>
<tr>
<th data-column="0">ID</th>
<th data-column="1">First Name</th>
<th data-column="2">Last Name</th>
<th data-column="3">Address</th>
<th data-column="4">Age</th>
</tr>
</tbody>
</table>
<p>
Click on column headings to sort data rows.
</p>
<p>
Source code: <a href="index.js">index.js</a>
</p>
</body>
</html>

59
examples/table/index.js Normal file
View File

@ -0,0 +1,59 @@
assertion type person(id, firstName, lastName, address, age);
message type setSortColumn(number);
function newRow(id, firstName, lastName, address, age) {
actor {
react {
assert person(id, firstName, lastName, address, age);
}
}
}
function spawnModel() {
newRow(1, 'Keith', 'Example', '94 Main St.', 44);
newRow(2, 'Karen', 'Fakeperson', '5504 Long Dr.', 34);
newRow(3, 'Angus', 'McFictional', '2B Pioneer Heights', 39);
newRow(4, 'Sue', 'Donnem', '1 Infinite Loop', 104);
newRow(5, 'Boaty', 'McBoatface', 'Arctic Ocean', 1);
}
function spawnView() {
actor {
var ui = new Syndicate.UI.Anchor();
var orderColumn = 2;
function cell(text) {
// Should escape text in a real application.
return '<td>' + text + '</td>';
}
react {
on message setSortColumn($c) { orderColumn = c; }
during person($id, $firstName, $lastName, $address, $age) {
assert ui.context(id)
.html('table#the-table tbody',
'<tr>' + [id, firstName, lastName, address, age].map(cell).join('') + '</tr>',
[id, firstName, lastName, address, age][orderColumn]);
}
}
}
}
function spawnController() {
actor {
react {
on message Syndicate.UI.globalEvent('table#the-table th', 'click', $e) {
:: setSortColumn(JSON.parse(e.target.dataset.column));
}
}
}
}
ground dataspace G {
Syndicate.UI.spawnUIDriver();
spawnModel();
spawnView();
spawnController();
}