Skip to content

Instantly share code, notes, and snippets.

@rugyoga
Last active June 23, 2022 19:44
Show Gist options
  • Save rugyoga/7cac7f4147225a72095ca292b5c32313 to your computer and use it in GitHub Desktop.
Save rugyoga/7cac7f4147225a72095ca292b5c32313 to your computer and use it in GitHub Desktop.
refactoring exercise
function pdf_variants(baseUrl) {
return {
rawUri: baseUrl + '_raw.pdf',
rawX1a: baseUrl + '_raw.pdfx',
rawNonX1a: baseUrl + '_raw_non_x1a.pdf',
proofUri: baseUrl + '.pdf',
proofX1a: baseUrl + '.pdfx',
proofNonX1a: baseUrl + '_non_x1a.pdf',
}
}
function baseUrl(id) {
return '/' + id.substring(id.indexOf('_') + 1) + '/' + id;
}
function getWhatsRequired(msg) {
const ld_flag = function(flag) { return msg.launch_darkly_flags[flag] === 1; }
return {
id,
resource_type: msg.resource_type,
receiptHandle: msg.receiptHandle,
pdfs: pdf_variants(baseUrl(msg.resource.id)),
usePreflight: ld_flag(msg, 'picasso.use_preflight'),
strictPreflight: ld_flag(msg, 'picasso.strict_preflight'),
};
}
@landonbar
Copy link

love how much cleaner this is! probably would want to use anonymous functions for performance reasons, but otherwise think it's much more readable
https://dmitripavlutin.com/differences-between-arrow-and-regular-functions/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment