From 6914d99bda53f7732988a61b639165b54d9b8cfd Mon Sep 17 00:00:00 2001 From: Adam Byrtek Date: Tue, 24 Feb 2015 20:18:14 +0000 Subject: Trigger onData on widget initialization --- javascripts/dashing.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index e5875d8..c66128d 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -40,7 +40,12 @@ class Dashing.Widget extends Batman.View @mixin($(@node).data()) Dashing.widgets[@id] ||= [] Dashing.widgets[@id].push(@) - @mixin(Dashing.lastEvents[@id]) # in case the events from the server came before the widget was rendered + + # In case the events from the server came before the widget was rendered + lastData = Dashing.lastEvents[@id] + if lastData + @mixin(lastData) + @onData(lastData) type = Batman.Filters.dashize(@view) $(@node).addClass("widget widget-#{type} #{@id}") -- cgit v1.2.3 From e18a162b663e5e0a924d3a884ad1c64f75e8cf8d Mon Sep 17 00:00:00 2001 From: Adam Byrtek Date: Tue, 24 Feb 2015 20:57:59 +0000 Subject: Store last events for all widgets Even the ones that haven't been initialized yet. --- javascripts/dashing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index c66128d..f41a279 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -114,8 +114,8 @@ source.addEventListener 'message', (e) -> if lastEvents[data.id]?.updatedAt != data.updatedAt if Dashing.debugMode console.log("Received data for #{data.id}", data) + lastEvents[data.id] = data if widgets[data.id]?.length > 0 - lastEvents[data.id] = data for widget in widgets[data.id] widget.receiveData(data) -- cgit v1.2.3 From c49e181cdb13d3357d76759e5311746ffe00f281 Mon Sep 17 00:00:00 2001 From: Adam Byrtek Date: Tue, 24 Feb 2015 21:00:13 +0000 Subject: Send last event data when a widget is ready --- javascripts/dashing.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index f41a279..20a9987 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -41,12 +41,6 @@ class Dashing.Widget extends Batman.View Dashing.widgets[@id] ||= [] Dashing.widgets[@id].push(@) - # In case the events from the server came before the widget was rendered - lastData = Dashing.lastEvents[@id] - if lastData - @mixin(lastData) - @onData(lastData) - type = Batman.Filters.dashize(@view) $(@node).addClass("widget widget-#{type} #{@id}") @@ -60,6 +54,12 @@ class Dashing.Widget extends Batman.View @::on 'ready', -> Dashing.Widget.fire 'ready' + # In case the events from the server came before the widget was rendered + lastData = Dashing.lastEvents[@id] + if lastData + @mixin(lastData) + @onData(lastData) + receiveData: (data) => @mixin(data) @onData(data) -- cgit v1.2.3