Skip to content

Use of $http improvements #23

@ThomasBurleson

Description

@ThomasBurleson

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 ]
  ));
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions