diff --git a/angular-cached-resource.js b/angular-cached-resource.js index 259e0af..7bb1e28 100644 --- a/angular-cached-resource.js +++ b/angular-cached-resource.js @@ -1,5 +1,4 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o - resource = CachedResource.$resource[name](params) - resource.$promise.then (response) -> + resource = CachedResource.$resource[name](params, (response, headers) -> newArrayInstance = new Array() response.map (resourceInstance) -> @@ -49,20 +48,24 @@ module.exports = readArrayCache = ($q, providerParams, name, CachedResource, act newArrayInstance.push resourceInstance arrayInstance.splice(0, arrayInstance.length, newArrayInstance...) + arrayInstance.headers = headers() cacheDeferred.resolve arrayInstance unless cacheArrayEntry.value httpDeferred.resolve arrayInstance - resource.$promise.catch (error) -> + , (error) -> cacheDeferred.reject error unless cacheArrayEntry.value httpDeferred.reject error + ) if not actionConfig.cacheOnly CachedResource.$writes.flush readHttp if cacheArrayEntry.value - for cacheInstanceParams in cacheArrayEntry.value + for cacheInstanceParams in cacheArrayEntry.value.data cacheInstanceEntry = new ResourceCacheEntry(CachedResource.$key, cacheInstanceParams).load() arrayInstance.push new CachedResource cacheInstanceEntry.value + if cacheArrayEntry.value.headers + arrayInstance.headers = cacheArrayEntry.value.headers # Resolve the promise as the cache is ready cacheDeferred.resolve arrayInstance diff --git a/src/resource_cache_array_entry.coffee b/src/resource_cache_array_entry.coffee index b0c6d4c..b9f046b 100644 --- a/src/resource_cache_array_entry.coffee +++ b/src/resource_cache_array_entry.coffee @@ -7,8 +7,11 @@ module.exports = (providerParams) -> cacheKeyPrefix: -> "#{@key}/array" addInstances: (instances, dirty, options = {append: false}) -> - cacheArrayReferences = if options.append then @value else [] - cacheArrayReferences ?= [] + cacheArrayReferences = {} + cacheArrayReferences.data = if options.append then @value else [] + cacheArrayReferences.data ?= [] + if instances.headers + cacheArrayReferences.headers = instances.headers for instance in instances cacheInstanceParams = instance.$params() @@ -17,7 +20,7 @@ module.exports = (providerParams) -> '#{@key}' instance doesn't have any boundParams. Please, make sure you specified them in your resource's initialization, f.e. `{id: "@id"}`, or it won't be cached. """ else - cacheArrayReferences.push cacheInstanceParams + cacheArrayReferences.data.push cacheInstanceParams cacheInstanceEntry = new ResourceCacheEntry(@key, cacheInstanceParams).load() # if we're appending and there's already a resource entry, we won't clobber external intent (eg. $save) about that resource unless options.append and cacheInstanceEntry.value?