UNPKG

angular-cached-resource

Version:

An AngularJS module to interact with RESTful resources, even when browser is offline

43 lines (35 loc) 1.95 kB
// Generated by CoffeeScript 1.7.1 var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; module.exports = function(providerParams) { var $log, ResourceCacheArrayEntry, ResourceCacheEntry; $log = providerParams.$log; ResourceCacheEntry = require('./resource_cache_entry')(providerParams); return ResourceCacheArrayEntry = (function(_super) { __extends(ResourceCacheArrayEntry, _super); function ResourceCacheArrayEntry() { return ResourceCacheArrayEntry.__super__.constructor.apply(this, arguments); } ResourceCacheArrayEntry.prototype.defaultValue = []; ResourceCacheArrayEntry.prototype.cacheKeyPrefix = function() { return "" + this.key + "/array"; }; ResourceCacheArrayEntry.prototype.addInstances = function(instances, dirty) { var cacheArrayReferences, cacheInstanceEntry, cacheInstanceParams, instance, _i, _len; cacheArrayReferences = []; for (_i = 0, _len = instances.length; _i < _len; _i++) { instance = instances[_i]; cacheInstanceParams = instance.$params(); if (Object.keys(cacheInstanceParams).length === 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(this.key, cacheInstanceParams).load(); cacheInstanceEntry.set(instance, dirty); } } return this.set(cacheArrayReferences, dirty); }; return ResourceCacheArrayEntry; })(ResourceCacheEntry); };