Created
June 22, 2015 17:16
-
-
Save michelleminkoff/98c92ee709d5169ebbbf to your computer and use it in GitHub Desktop.
Require conditional loading
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
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