Created
June 24, 2019 00:09
-
-
Save deconstructionalism/e07ab4f01c5d429d78536c2764454f09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const materials = [ | |
'course_work', | |
'course_work', | |
'exam', | |
'project', | |
'course_work' | |
] | |
const wrapPolymorphicAction = (action) => { | |
const polymorphicWrapper = function (action) { | |
return function () { | |
const args = Array.from(arguments) | |
const materialId = args[0] | |
const materialType = materials[materialId] | |
const controller = `controller for ${materialType} as parent` | |
action.apply(this, [...args, controller]) | |
} | |
} | |
const wrappedAction = polymorphicWrapper(action) | |
return wrappedAction | |
} | |
const getGradableChunk = (materialId, id, controller, trx) => { | |
console.log(controller) | |
return { | |
content: 'stuff', | |
name: 'thing', | |
material_type: 'course_work' | |
} | |
} | |
const wrappedGetGradableChunk = wrapPolymorphicAction(getGradableChunk) | |
wrappedGetGradableChunk(3, 45) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment