Skip to content

Instantly share code, notes, and snippets.

@kdimatteo
Created April 17, 2014 13:53
Show Gist options
  • Save kdimatteo/10985171 to your computer and use it in GitHub Desktop.
Save kdimatteo/10985171 to your computer and use it in GitHub Desktop.
Ember Image Cache with ActiveModelSerializer
//todo: memory hit with this loop?
//todo: check for valid file names (or use a "cacheThisKey" setting in the model?)
DS.ActiveModelSerializer.reopen({
createImageCaches: function(hash){
window.imageCache = window.imageCache || [];
var imageKeys = ['url', 'photo_url', 'image_url', 'image'];
for(var k in hash){
if(imageKeys.contains(k)){
var i = new Image();
i.src = hash[k];
window.imageCache.push(i);
}
};
},
normalize: function(type, hash, prop) {
this.normalizeLinks(hash);
this.createImageCaches(hash);
return this._super(type, hash, prop);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment