Skip to content

Commit

Permalink
feat(plugins): new plugin api including explicit support for es5 and …
Browse files Browse the repository at this point in the history
…at script
  • Loading branch information
EisenbergEffect committed Jan 21, 2015
1 parent 3465e84 commit b5c588b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/aurelia.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Aurelia {
this.container = container || new Container();
this.resources = resources || new ResourceRegistry();
this.resourcesToLoad = [];
this.plugins = new Plugins(this);
this.use = new Plugins(this);

if(!this.resources.baseResourcePath){
this.resources.baseResourcePath = System.baseUrl || '';
Expand Down Expand Up @@ -105,7 +105,7 @@ export class Aurelia {
this.started = true;
logger.info('Aurelia Starting');

return this.plugins.process().then(() => {
return this.use._process().then(() => {
if(!this.container.hasHandler(BindingLanguage)){
logger.error('You must configure Aurelia with a BindingLanguage implementation.');
}
Expand Down
34 changes: 31 additions & 3 deletions src/plugins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as LogManager from 'aurelia-logging';
import {addFunctionMetadataLocation} from 'aurelia-metadata';

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

Expand Down Expand Up @@ -43,17 +44,44 @@ export class Plugins {
/**
* Installs a plugin before Aurelia starts.
*
* @method install
* @method plugin
* @param {moduleId} moduleId The ID of the module to install.
* @param {config} config The configuration for the specified module.
* @return {Plugins} Returns the current Plugins instance.
*/
install(moduleId, config){
plugin(moduleId, config){
this.info.push({moduleId:moduleId, config:config});
return this;
}

process(){
/**
* Installs special support for ES5 authoring.
*
* @method es5
* @return {Plugins} Returns the current Plugins instance.
*/
es5(){
Function.prototype.computed = function(computedProperties){
for(var key in computedProperties){
if(computedProperties.hasOwnProperty(key)){
Object.defineProperty(this.prototype, key, { get: prop[key], enumerable: true });
}
}
}
}

/**
* Installs special support for AtScript authoring.
*
* @method atscript
* @return {Plugins} Returns the current Plugins instance.
*/
atscript(){
this.aurelia.container.supportAtScript();
addFunctionMetadataLocation('annotate');
}

_process(){
var aurelia = this.aurelia,
loader = aurelia.loader,
info = this.info,
Expand Down

0 comments on commit b5c588b

Please sign in to comment.