Precompile location example. Requires rename location -> locationRecord to avoid window.location clash.

This commit is contained in:
Tony Garnock-Jones 2016-06-11 07:03:39 -04:00
parent ddd67540be
commit 9b2ce64300
4 changed files with 20 additions and 12 deletions

1
js/examples/location/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.expanded.js

View File

@ -0,0 +1,7 @@
all: index.expanded.js
%.expanded.js: %.js
../../bin/syndicatec $< > $@ || (rm -f $@; false)
clean:
rm -f *.expanded.js

View File

@ -8,9 +8,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.1/mustache.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.1/mustache.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.3.0/js/md5.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.3.0/js/md5.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAgjLSNu9Cx4V1bNxhSTM4ZzqADbGoYmZ0"></script> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAgjLSNu9Cx4V1bNxhSTM4ZzqADbGoYmZ0"></script>
<script src="../../dist/syndicatecompiler.js"></script> <script src="../../dist/syndicate.min.js"></script>
<script src="../../dist/syndicate.js"></script>
<script type="text/syndicate-js" src="index.js"></script>
</head> </head>
<body> <body>
<template id="json"> <template id="json">
@ -48,5 +46,7 @@
<button id="findMarker">Find</button> <button id="findMarker">Find</button>
</fieldset> </fieldset>
</div> </div>
<script src="index.expanded.js"></script>
</body> </body>
</html> </html>

View File

@ -1,4 +1,4 @@
assertion type location(id, email, timestamp, lat, lng); assertion type locationRecord(id, email, timestamp, lat, lng) = 'location';
message type findMarker(id); message type findMarker(id);
var brokerConnection = Syndicate.Broker.brokerConnection; var brokerConnection = Syndicate.Broker.brokerConnection;
@ -44,11 +44,11 @@ ground dataspace G {
var watchId = ('geolocation' in navigator) var watchId = ('geolocation' in navigator)
&& navigator.geolocation.watchPosition(Syndicate.Dataspace.wrap(function (pos) { && navigator.geolocation.watchPosition(Syndicate.Dataspace.wrap(function (pos) {
:: location(id, :: locationRecord(id,
email_element.value.trim(), email_element.value.trim(),
+new Date(), +new Date(),
pos.coords.latitude, pos.coords.latitude,
pos.coords.longitude); pos.coords.longitude);
if (!mapInitialized && map) { if (!mapInitialized && map) {
mapInitialized = true; mapInitialized = true;
map.setCenter({lat: pos.coords.latitude, lng: pos.coords.longitude}); map.setCenter({lat: pos.coords.latitude, lng: pos.coords.longitude});
@ -78,11 +78,11 @@ ground dataspace G {
:: findMarker(document.getElementById('markerList').value); :: findMarker(document.getElementById('markerList').value);
} }
on message ($loc = location(_, _, _, _, _)) { on message ($loc = locationRecord(_, _, _, _, _)) {
currentLocation = loc; currentLocation = loc;
} }
during fromBroker(wsurl, location($id, $email, _, _, _)) { during fromBroker(wsurl, locationRecord($id, $email, _, _, _)) {
var ui = new Syndicate.UI.Anchor(); var ui = new Syndicate.UI.Anchor();
var marker = new google.maps.Marker({ var marker = new google.maps.Marker({
map: map, map: map,
@ -123,7 +123,7 @@ ground dataspace G {
selectMarker(); selectMarker();
if (latestPosition) map.panTo(latestPosition); if (latestPosition) map.panTo(latestPosition);
} }
on asserted fromBroker(wsurl, location(id, email, $timestamp, $lat, $lng)) { on asserted fromBroker(wsurl, locationRecord(id, email, $timestamp, $lat, $lng)) {
latestTimestamp = new Date(timestamp); latestTimestamp = new Date(timestamp);
latestPosition = {lat: lat, lng: lng}; latestPosition = {lat: lat, lng: lng};
marker.setPosition(latestPosition); marker.setPosition(latestPosition);