diff options
author | Daniel Beauchamp <daniel.beauchamp@gmail.com> | 2015-07-10 14:14:17 -0400 |
---|---|---|
committer | Daniel Beauchamp <daniel.beauchamp@gmail.com> | 2015-07-10 14:14:17 -0400 |
commit | 5a0bdd90aaf368b8078c594d9cbde2d2cb60ea0d (patch) | |
tree | e93a887f0960d636e0e6f257a1c4f5727793b00b | |
parent | 4991e098c085e928e1b25776680727db4963d374 (diff) | |
parent | c49e181cdb13d3357d76759e5311746ffe00f281 (diff) |
Merge pull request #521 from adambyrtek/last-event-triggers-ondata
Trigger onData on widget initialization
-rw-r--r-- | javascripts/dashing.coffee | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index e5875d8..20a9987 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -40,7 +40,6 @@ 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 type = Batman.Filters.dashize(@view) $(@node).addClass("widget widget-#{type} #{@id}") @@ -55,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) @@ -109,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) |