Changeset - 5f31e02fbf70
[Not reviewed]
default
0 1 0
Drew Perttula - 6 years ago 2019-06-01 02:26:05
drewp@bigasterisk.com
live page stays on the same effect when you reload, now that it writes effectChoice to the url
Ignore-this: f1143abd07d4775f97868abaf32d359c
1 file changed with 18 insertions and 0 deletions:
0 comments (0 inline, 0 general)
light9/web/live/live.coffee
Show inline comments
 
@@ -342,6 +342,9 @@ class GraphToControls
 
    @activeSettings.forAll(@_removeEffectSetting.bind(@))
 

	
 
  controlChanged: (device, deviceAttr, value) ->
 
    # todo: controls should be disabled if there's no effect and they won't do anything.
 
    return if not @effect
 
    
 
    # value is float or #color or (Uri or null)
 
    if (value == undefined or (typeof value == "number" and isNaN(value)) or (typeof value == "object" and value != null and not value.id))
 
      throw new Error("controlChanged sent bad value " + value)
 
@@ -412,6 +415,7 @@ coffeeElementSetup(class Light9LiveContr
 
  constructor: ->
 
    super()
 
    @graphToControls = null
 
    @okToWriteUrl = false
 

	
 
  ready: ->
 
    super.ready()
 
@@ -425,9 +429,22 @@ coffeeElementSetup(class Light9LiveContr
 
    setTimeout(@setFromUrl.bind(@), 1)
 

	
 
  setFromUrl: ->
 
    # not a continuous bidi link between url and effect; it only reads
 
    # the url when the page loads.
 
    effect = new URL(window.location.href).searchParams.get('effect')
 
    if effect?
 
      log('found url', effect)
 
      @effectChoice = effect
 
    @okToWriteUrl = true
 

	
 
  writeToUrl: (effectStr) ->
 
    return unless @okToWriteUrl
 
    u = new URL(window.location.href)
 
    if u.searchParams.get('effect') == effectStr
 
      return        
 
    u.searchParams.set('effect', effectStr)
 
    window.history.replaceState({}, "", u.href)
 
    log('wrote new url', u.href)
 

	
 
  newEffect: ->
 
    @effectChoice = @graphToControls.newEffect().value
 
@@ -440,6 +457,7 @@ coffeeElementSetup(class Light9LiveContr
 
    else
 
      log('load', @effectChoice)
 
      @graphToControls.setEffect(@graph.Uri(@effectChoice)) if @graphToControls?
 
    @writeToUrl(@effectChoice)
 
 
 
  clearAll: ->
 
    # clears the effect!
0 comments (0 inline, 0 general)