-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackbone.cache.min.js
1 lines (1 loc) · 1.3 KB
/
backbone.cache.min.js
1
(function(a,b){if(b.Cache){return}b.Cache=function(){this.store={}};a.extend(b.Cache.prototype,b.Events,{set:function(c,d){this.trigger("set",c,d);this.store[c]=d},has:function(c){var d=!!this.store[c];this.trigger("has",c,d);return d},get:function(c){var d=this.store[c];this.trigger("get",c,d);return d},remove:function(c){var d=this.store[c];this.trigger("remove",c,d);delete this.store[c];return d},clear:function(){this.trigger("clear");this.store={}}});b.CachedCollection=b.Collection.extend({fetch:function(c){if(this.cacheKey&&this.cacheObject){var d=this.cacheObject,g=this.cacheKey;if(d.has(g)){var f=d.get(g),h=c.update?"update":"reset";this[h](f,c);if(c.success){c.success(this,f,c)}return a.Deferred().resolve()}else{var e=c.success;c.success=function(i,k,j){d.set(g,k);if(e){e(i,k,j)}};return b.Collection.prototype.fetch.call(this,c)}}else{return b.Collection.prototype.fetch.call(this,c)}}});b.CachedModel=b.Model.extend({fetch:function(c){if(this.cacheKey&&this.cacheObject){c=c||{};var d=this.cacheObject,g=this.cacheKey,f=c.success;if(d.has(g)){var e=d.get(g);this.set(this.parse(e,c),c);if(f){f(this,e,c)}return a.Deferred().resolve()}else{c.success=function(h,j,i){d.set(g,j);if(f){f(h,j,i)}};return b.Model.prototype.fetch.call(this,c)}}else{return b.Model.prototype.fetch.call(this,c)}}})})(jQuery,Backbone);