Files
side-by-side/source/scripts/services/fetch.js.coffee
T
2014-12-21 21:14:13 +01:00

18 lines
503 B
CoffeeScript

angular.module("sideBySide").factory "fetch", ['$http', '$q', 'readerFactory', ($http, $q, readerFactory) ->
# Fetch
#
# @param base [String] Path to config file directory
# @return [Object] Promises and config data
(base) ->
file = base + '/config.json'
$http.get(file).then (config) ->
promises = config.data.files.map (poem) ->
$http.get(base + '/' + poem).then (response) ->
readerFactory(poem) response.data
{
fetchedPoems: $q.all promises
data: config.data
}
]