Created
October 20, 2016 11:44
-
-
Save BartKrol/494427195970f097b23c2478f273bddc to your computer and use it in GitHub Desktop.
Which one is better
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
function interceptLoadFunctions(name, loader) { | |
return Object.assign({}, loader, { | |
load(id) { | |
return loader.load(id).catch(itemErrorHandler(name, id)) | |
}, | |
loadMany(ids, ...args) { | |
return loader.loadMany(ids).catch(multipleItemsErrorHandler(name, ids)) | |
} | |
}) | |
} | |
class Loader extends DataLoader { | |
constructor(...args) { | |
super(args) | |
} | |
load(id) { | |
return super.load(id).catch(itemErrorHandler(name, id)) | |
} | |
loadMany(ids) { | |
return super.loadMany(ids).catch(multipleItemsErrorHandler(name, ids)) | |
} | |
} | |
class Loader2 { | |
constructor(...args) { | |
this.loader = new Loader(...args) | |
} | |
load(id) { | |
return this.loader.load(id).catch(itemErrorHandler(name, id)) | |
} | |
loadMany(ids) { | |
return this.loader.loadMany(ids).catch(multipleItemsErrorHandler(name, ids)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment