diff light9/web/light9-music.coffee @ 1731:e06c2c105035

workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all Ignore-this: 192b2826e728db8b7ca6cfb67609241e
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 14 May 2018 02:10:05 +0000
parents f24d4b331f15
children 7fe81130b735
line wrap: on
line diff
--- a/light9/web/light9-music.coffee	Sat May 12 23:02:26 2018 +0000
+++ b/light9/web/light9-music.coffee	Mon May 14 02:10:05 2018 +0000
@@ -1,9 +1,9 @@
 log = console.log
 
 # port of light9/curvecalc/musicaccess.py
-Polymer
-  is: "light9-music",
-  properties:
+coffeeElementSetup(class Music extends Polymer.Element
+  @is: "light9-music",
+  @getter_properties:
     status: { type: String, notify: true }
     statusTitle: { type: String, notify: true }
     turboSign: { type: String, notify: true }
@@ -16,15 +16,16 @@
     t: { type: Number, notify: true }
     
   ready: ->
+    super.ready()
     @turboUntil = 0
-    @$.getTime.addEventListener('response', @onResponse.bind(@))
-    @$.getTime.addEventListener 'error', (e) =>
-      req = @$.getTime.lastRequest
-      @status = "✘"
-      @statusTitle = "GET "+req.url+ " -> " + req.status + " " + req.statusText
-      setTimeout(@poll.bind(@), 2000)
     @poll()
     setInterval(@estimateTimeLoop.bind(@), 30)
+
+  onError: (e) ->
+    req = @$.getTime.lastRequest
+    @status = "✘"
+    @statusTitle = "GET "+req.url+ " -> " + req.status + " " + req.statusText
+    setTimeout(@poll.bind(@), 2000)
     
   estimateTimeLoop: ->
     if @playing
@@ -33,6 +34,9 @@
       @t = @remoteT
     
   poll: ->
+    if not @$?.getTime?
+      setTimeout(@poll.bind(@), 200)
+      return
     clearTimeout(@nextPoll) if @nextPoll
     @$.getTime.generateRequest()
     @status = "♫"
@@ -65,4 +69,5 @@
     
     @turboUntil = Date.now() + 1000
     @poll()
-    
+)
+