Only fetch poems once

This commit is contained in:
Vit Brunner
2014-10-02 22:41:54 +02:00
parent 19e4fc957a
commit ab4daea5a3
@@ -1,15 +1,21 @@
angular.module("sideBySide").service "poems", ['$rootScope', '$q', 'fetch', ($rootScope, $q, fetch) ->
poems = []
loaded = false
heading = undefined
@update = (config) ->
fetch(config).then((result) ->
$q.all(result.promises).then((results) ->
poems = results
heading = result.heading
$rootScope.$emit "poemsLoaded"
if loaded == true
$rootScope.$emit "poemsLoaded"
else
fetch(config).then((result) ->
$q.all(result.promises).then((results) ->
poems = results
heading = result.heading
loaded = true
$rootScope.$emit "poemsLoaded"
)
)
)
@get = () ->
poems