Last active
July 18, 2017 05:59
-
-
Save idealley/1066aca705b768e5f869674e489347c3 to your computer and use it in GitHub Desktop.
Method to refactor with currying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parseAttachements: (item, baseUrl, images, documents) => { | |
images = images || []; | |
documents = documents || []; | |
return _.mapValues(item, (v, k) => { | |
if(images.indexOf(k) != -1 && k === 'highResImage' && v) { | |
return self.attachementUrl(baseUrl, 'preview', v, 1800) | |
} ; | |
if(images.indexOf(k) != -1) { | |
if(_.isArray(v) ) { | |
return _.map(v, c => { | |
if(c.image) { | |
self.attachementUrl(baseUrl, 'preview', c.image, 500) | |
} | |
return c; | |
}); | |
} | |
if(k !== 'highResImage') { return self.attachementUrl(baseUrl, 'preview', v, 1800); } | |
} | |
if(documents.indexOf(k) != -1 && v) { | |
return self.attachementUrl(baseUrl, 'static', v, 500); | |
} | |
//make sure to return false for those properties that were untouched | |
if(documents.indexOf(k) != -1 || images.indexOf(k) != -1) | |
{ return false; } | |
//make sure to return all other values untouched | |
return v; | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment