angular-cached-resource
Version:
An AngularJS module to interact with RESTful resources, even when browser is offline
22 lines (19 loc) • 928 B
text/coffeescript
module.exports = (providerParams) ->
{$log} = providerParams
ResourceCacheEntry = require('./resource_cache_entry')(providerParams)
class ResourceCacheArrayEntry extends ResourceCacheEntry
defaultValue: []
cacheKeyPrefix: -> "#{@key}/array"
addInstances: (instances, dirty) ->
cacheArrayReferences = []
for instance in instances
cacheInstanceParams = instance.$params()
if Object.keys(cacheInstanceParams).length is 0
$log.error """
instance #{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
cacheInstanceEntry = new ResourceCacheEntry(@key, cacheInstanceParams).load()
cacheInstanceEntry.set instance, dirty
@set cacheArrayReferences, dirty