JSFiddle - React, Tailwind, and code Playground
by Chase Wilson
JavaScript
require.config({
packages:{
name: 'modules'
,location:'app/modules'
}
})
// blocks/block.js
define(function(){
var Block = new Class({
...
init: function(module,options){
// Some how figure out where this module is located based off
// what was provided. Mapping || what have you. In this case
// we jsut split the dot and assume a path
module = module.split('.');
module = ['modules',module[0],module[1]].join('/');
this.setModule( module );
}
setModule: function(module){
var self = this;
// attempt to load and use /twitter/feed.js module
require([module],function(Module){
// Module here is expected to be modules/twitter/feed
self.module = new Module(self.options);
})
}
...
});
return Block;
});
// init.js
define(['blocks/block',function(Block){
var Template = {
// create a block passing a reference to the dynamic module
// that this template depends on
// in this case `path-to-modules`/twitter/feed.js
master: new Block('twitter.feed',{});
}
});