Skip to content

Instantly share code, notes, and snippets.

@michelleminkoff
Created June 22, 2015 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelleminkoff/98c92ee709d5169ebbbf to your computer and use it in GitHub Desktop.
Save michelleminkoff/98c92ee709d5169ebbbf to your computer and use it in GitHub Desktop.
Require conditional loading
define(['module', 'jquery'], function(module, $) {
return {
//in a plugin, we always give a load function for require to execute
load: function(id, require, load, config) {
//set up an object matching up a "type" to a library path. The paths I included may not be correct, I just roughed them out
var typeToLoad = {
'video': 'ap/video',
'audio': 'ap/audio'
}
//the "type" should be attached to the overall module back on app.js, here I assume it's saved to the module as questionType
var rawQuestionType = module.questionType
//Use the "path" for this question, and our lookup object, to determine what conditional path to load
//If the "type" is not found in our lookup object, we return false
var questionLibPath = typeToLoad[rawQuestionType] || false;
//if this question's "type" has a conditional path, then load that conditional path
if (questionLibPath) {
require([questionLibPath], load);
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment