-
Notifications
You must be signed in to change notification settings - Fork 131
Open
Labels
Description
Your do not need to wrap $http()
calls with $q.defer()
usages.
var find = function () {
var deferred = $q.defer();
var url = ENDPOINT_URI + 'clients/' + AuthService.getCurrentUserId() + '/stories.json';
$http.get(url).success(deferred.resolve).error(deferred.reject);
return deferred.promise;
};
And consolidate all URLs into a url map. Consider this result:
var URLS = {
STORY : {
findAll : "{0}/clients/{1}/stories.json"
, loadStoryDetails : "{0}/clients/{1}/stories/{2}.json"
}
};
function findAllStories( )
{
return $http.get( supplant(
URLS.STORY.findAll, [ ENDPOINT_URI, AuthService.getCurrentUserId() ]
));
}
function loadStory( storyID )
{
return $http.get( supplant(
URLS.STORY.loadStory, [ ENDPOINT_URI, AuthService.getCurrentUserId(), storyID ]
));
}