dist/hypermedia.js
function extractAndUpdateResources(data, links, rootResource, resource) {
      var resources = [];

      var selfHref = ((data._links || {}).self || {}).href;
      if (!selfHref) {
        throw new Error('Self link href expected but not found');
      }

      // Extract links
      angular.extend(links, data._links);
      delete data._links;

      // Extract and update embedded resources
      Object.keys(data._embedded || {}).forEach(function (rel) {
        var embeds = data._embedded[rel];

        // Add link to embedded resource if missing
        if (!(rel in links)) {
          links[rel] = forArray(embeds, function (embedded) {
            return {href: embedded._links.self.href};
          });
        }
        // Recurse into embedded resource
        forArray(embeds, function (embedded) {
          resources = resources.concat(extractAndUpdateResources(embedded, {}, rootResource, null));
        });
      });
      delete data._embedded;

      // Update resource
      if (!resource) resource = rootResource.$context.get(links.self.href, rootResource.constructor);
      Resource.prototype.$update.call(resource, data, links);
      resources.push(resource);

      return resources;
    }
function extractAndUpdateResources(data, links, rootResource, resource) {
      var resources = [];

      var selfHref = ((data._links || {}).self || {}).href;
      if (!selfHref) {
        throw new Error('Self link href expected but not found');
      }

      // Extract links
      angular.extend(links, data._links);
      delete data._links;

      // Extract and update embedded resources
      Object.keys(data._embedded || {}).forEach(function (rel) {
        var embeds = data._embedded[rel];

        // Add link to embedded resource if missing
        if (!(rel in links)) {
          links[rel] = forArray(embeds, function (embedded) {
            return {href: embedded._links.self.href};
          });
        }
        // Recurse into embedded resource
        forArray(embeds, function (embedded) {
          resources = resources.concat(extractAndUpdateResources(embedded, {}, rootResource, null));
        });
      });
      delete data._embedded;

      // Update resource
      if (!resource) resource = rootResource.$context.get(links.self.href, rootResource.constructor);
      Resource.prototype.$update.call(resource, data, links);
      resources.push(resource);

      return resources;
    }
function extractAndUpdateResources ( data , links , rootResource , resource ) { var resources = [ ] ; var selfHref = ( ( data . _links || { } ) . self || { } ) . href ; if ( ! selfHref ) { throw new Error ( 'Self link href expected but not found' ) ; } // Extract links angular . extend ( links , data . _links ) ; delete data . _links ; // Extract and update embedded resources Object . keys ( data . _embedded || { } ) . forEach ( function ( rel ) { var embeds = data . _embedded [ rel ] ; // Add link to embedded resource if missing if ( ! ( rel in links ) ) { links [ rel ] = forArray ( embeds , function ( embedded ) { return { href : embedded . _links . self . href } ; } ) ; } // Recurse into embedded resource forArray ( embeds , function ( embedded ) { resources = resources . concat ( extractAndUpdateResources ( embedded , { } , rootResource , null ) ) ; } ) ; } ) ; delete data . _embedded ; // Update resource if ( ! resource ) resource = rootResource . $context . get ( links . self . href , rootResource . constructor ) ; Resource . prototype . $update . call ( resource , data , links ) ; resources . push ( resource ) ; return resources ; }
Recursively extract embedded resources and update them in the context, then update the resource itself.

@param {object} data
@param {object} [links]
@param {Resource} rootResource
@param {Resource} resource
Recursively extract embedded resources and update them in the context then update the resource itself .