Skip to content

Commit

Permalink
feat(framework): enable plugin loading and config
Browse files Browse the repository at this point in the history
A new api has been added to the aurelia class called withPlugin which
allows you to specify a module id and a config. When you call
aurelia.start all plugins will be dynamically loaded and their install
methods will be called with the config object. install is options. If
present, it may return a promise.
  • Loading branch information
EisenbergEffect committed Dec 22, 2014
1 parent 9a41280 commit f3b02ea
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/aurelia.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,33 @@ import {EventAggregator, includeEventsIn} from 'aurelia-event-aggregator';

var logger = LogManager.getLogger('aurelia');

function loadPlugins(loader, plugins){
var toLoad = [], i, ii, current;

for(i = 0, ii = plugins.length; i < ii; ++i){
current = plugins[i];
logger.debug(`Loading plugin ${current.moduleId}.`);
toLoad.push(loader.loadModule(current.moduleId).then(exportedValue => {
if('install' in exportedValue){
return exportedValue.install(current.config || {}).then(() =>{
logger.debug(`Installed plugin ${current.moduleId}.`);
});
}else{
logger.debug(`Loaded plugin ${current.moduleId}.`);
}
}));
}

return Promise.all(toLoad);
}

export class Aurelia {
constructor(loader, container, resources){
this.loader = loader || Loader.createDefaultLoader();
this.container = container || new Container();
this.resources = resources || new ResourceRegistry();
this.resourcesToLoad = [];
this.plugins = [];

this.withInstance(Aurelia, this);
this.withInstance(Loader, this.loader);
Expand All @@ -34,8 +55,8 @@ export class Aurelia {
return this;
}

withPlugins(config, baseUrl){
logger.error('withPlugins is not yet implemented');
withPlugin(moduleId, config){
this.plugins.push({moduleId:moduleId, config:config});
return this;
}

Expand All @@ -61,14 +82,14 @@ export class Aurelia {
logger.error('You must configure Aurelia with a BindingLanguage implementation.');
}

//TODO: configure plugins

return this.container.get(ResourceCoordinator)
.importResources(this.resourcesToLoad).then(resources => {
resources.forEach(x => x.register(this.resources));
logger.info('Aurelia Started');
return this;
});
return loadPlugins(this.loader, this.plugins).then(() => {
return this.container.get(ResourceCoordinator)
.importResources(this.resourcesToLoad).then(resources => {
resources.forEach(x => x.register(this.resources));
logger.info('Aurelia Started');
return this;
});
});
}

setRoot(root, applicationHost){
Expand Down

0 comments on commit f3b02ea

Please sign in to comment.