From c985b35bb58ef0be4dd657a20bbf319a198c573b Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Sun, 18 Jun 2017 19:38:29 +0100 Subject: [PATCH] create monitor.js page for Monitor.cshtml page --- RaceLapTimer/RaceLapTimer/www/js/monitor.js | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 RaceLapTimer/RaceLapTimer/www/js/monitor.js diff --git a/RaceLapTimer/RaceLapTimer/www/js/monitor.js b/RaceLapTimer/RaceLapTimer/www/js/monitor.js new file mode 100644 index 0000000..241c9b7 --- /dev/null +++ b/RaceLapTimer/RaceLapTimer/www/js/monitor.js @@ -0,0 +1,28 @@ +function ViewModel() { + "use strict"; + var self = this; + self.raceSessions = ko.observable(); + + $.get("/api/monitor", {}, self.raceSessions); + self.tmrHandle = setTimeout(function () { + self.getData(); + }, 2000); + + self.getData = function () { + $.get("/api/monitor", {}, self.raceSessions) + .done(function() { + console.log("done"); + }) + .always(function() { + self.tmrHandle = setTimeout(self.getData, 2000); + }); + }; +}; + +ViewModel.prototype.dispose = function () { + "use strict"; + window.clearInterval(self.tmrHandle); + console.log("disposed of timer"); +}; + +ko.applyBindings(new ViewModel()); \ No newline at end of file