Skip to content

Commit

Permalink
fix(plugins): preserve built-in plugin load order
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Aug 8, 2015
1 parent dd2547f commit 25a3529
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 303 deletions.
106 changes: 42 additions & 64 deletions dist/amd/aurelia-framework.js
Expand Up @@ -69,78 +69,56 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
return this;
};

Plugins.prototype.defaultBindingLanguage = function defaultBindingLanguage() {
Plugins.prototype._addNormalizedPlugin = function _addNormalizedPlugin(name, config) {
var _this2 = this;

this.aurelia.addPreStartTask(function () {
return System.normalize('aurelia-templating-binding', _this2.bootstrapperName).then(function (name) {
_this2.aurelia.use.plugin(name);
});
});
var plugin = { moduleId: name, resourcesRelativeTo: name, config: config || {} };

return this;
};

Plugins.prototype.router = function router() {
var _this3 = this;
this.plugin(plugin);

this.aurelia.addPreStartTask(function () {
return System.normalize('aurelia-templating-router', _this3.bootstrapperName).then(function (name) {
_this3.aurelia.use.plugin(name);
return System.normalize(name, _this2.bootstrapperName).then(function (normalizedName) {
normalizedName = normalizedName.endsWith('.js') || normalizedName.endsWith('.ts') ? normalizedName.substring(0, normalizedName.length - 3) : normalizedName;

plugin.moduleId = normalizedName;
plugin.resourcesRelativeTo = normalizedName;
System.map[name] = normalizedName;
});
});

return this;
};

Plugins.prototype.history = function history() {
var _this4 = this;
Plugins.prototype.defaultBindingLanguage = function defaultBindingLanguage() {
return this._addNormalizedPlugin('aurelia-templating-binding');
};

this.aurelia.addPreStartTask(function () {
return System.normalize('aurelia-history-browser', _this4.bootstrapperName).then(function (name) {
_this4.aurelia.use.plugin(name);
});
});
Plugins.prototype.router = function router() {
return this._addNormalizedPlugin('aurelia-templating-router');
};

return this;
Plugins.prototype.history = function history() {
return this._addNormalizedPlugin('aurelia-history-browser');
};

Plugins.prototype.defaultResources = function defaultResources() {
var _this5 = this;

this.aurelia.addPreStartTask(function () {
return System.normalize('aurelia-templating-resources', _this5.bootstrapperName).then(function (name) {
System.map['aurelia-templating-resources'] = name;
_this5.aurelia.use.plugin(name);
});
});

return this;
return this._addNormalizedPlugin('aurelia-templating-resources');
};

Plugins.prototype.eventAggregator = function eventAggregator() {
var _this6 = this;

this.aurelia.addPreStartTask(function () {
return System.normalize('aurelia-event-aggregator', _this6.bootstrapperName).then(function (name) {
System.map['aurelia-event-aggregator'] = name;
_this6.aurelia.use.plugin(name);
});
});

return this;
return this._addNormalizedPlugin('aurelia-event-aggregator');
};

Plugins.prototype.standardConfiguration = function standardConfiguration() {
return this.aurelia.use.defaultBindingLanguage().defaultResources().history().router().eventAggregator();
};

Plugins.prototype.developmentLogging = function developmentLogging() {
var _this7 = this;
var _this3 = this;

this.aurelia.addPreStartTask(function () {
return System.normalize('aurelia-logging-console', _this7.bootstrapperName).then(function (name) {
return _this7.aurelia.loader.loadModule(name).then(function (m) {
return System.normalize('aurelia-logging-console', _this3.bootstrapperName).then(function (name) {
return _this3.aurelia.loader.loadModule(name).then(function (m) {
_aureliaLogging.addAppender(new m.ConsoleAppender());
_aureliaLogging.setLevel(_aureliaLogging.logLevel.debug);
});
Expand All @@ -151,7 +129,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
};

Plugins.prototype._process = function _process() {
var _this8 = this;
var _this4 = this;

var aurelia = this.aurelia,
loader = aurelia.loader,
Expand All @@ -167,7 +145,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
return loadPlugin(aurelia, loader, current).then(next);
}

_this8.processed = true;
_this4.processed = true;
return Promise.resolve();
};

Expand Down Expand Up @@ -308,7 +286,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
};

Aurelia.prototype.start = function start() {
var _this9 = this;
var _this5 = this;

if (this.started) {
return Promise.resolve(this);
Expand All @@ -320,48 +298,48 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
preventActionlessFormSubmit();

return runTasks(this, this.preStartTasks).then(function () {
return _this9.use._process().then(function () {
if (!_this9.container.hasHandler(_aureliaTemplating.BindingLanguage)) {
return _this5.use._process().then(function () {
if (!_this5.container.hasHandler(_aureliaTemplating.BindingLanguage)) {
var message = 'You must configure Aurelia with a BindingLanguage implementation.';
logger.error(message);
throw new Error(message);
}

if (!_this9.container.hasHandler(_aureliaTemplating.Animator)) {
_aureliaTemplating.Animator.configureDefault(_this9.container);
if (!_this5.container.hasHandler(_aureliaTemplating.Animator)) {
_aureliaTemplating.Animator.configureDefault(_this5.container);
}

return loadResources(_this9.container, _this9.resourcesToLoad, _this9.resources);
return loadResources(_this5.container, _this5.resourcesToLoad, _this5.resources);
}).then(function () {
return runTasks(_this9, _this9.postStartTasks).then(function () {
return runTasks(_this5, _this5.postStartTasks).then(function () {
logger.info('Aurelia Started');
var evt = new window.CustomEvent('aurelia-started', { bubbles: true, cancelable: true });
document.dispatchEvent(evt);
return _this9;
return _this5;
});
});
});
};

Aurelia.prototype.enhance = function enhance() {
var _this10 = this;
var _this6 = this;

var bindingContext = arguments[0] === undefined ? {} : arguments[0];
var applicationHost = arguments[1] === undefined ? null : arguments[1];

this._configureHost(applicationHost);

return new Promise(function (resolve) {
var viewEngine = _this10.container.get(_aureliaTemplating.ViewEngine);
_this10.root = viewEngine.enhance(_this10.container, _this10.host, _this10.resources, bindingContext);
_this10.root.attached();
_this10._onAureliaComposed();
return _this10;
var viewEngine = _this6.container.get(_aureliaTemplating.ViewEngine);
_this6.root = viewEngine.enhance(_this6.container, _this6.host, _this6.resources, bindingContext);
_this6.root.attached();
_this6._onAureliaComposed();
return _this6;
});
};

Aurelia.prototype.setRoot = function setRoot() {
var _this11 = this;
var _this7 = this;

var root = arguments[0] === undefined ? 'app' : arguments[0];
var applicationHost = arguments[1] === undefined ? null : arguments[1];
Expand All @@ -379,10 +357,10 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
instruction.host = this.host;

return compositionEngine.compose(instruction).then(function (root) {
_this11.root = root;
_this7.root = root;
instruction.viewSlot.attached();
_this11._onAureliaComposed();
return _this11;
_this7._onAureliaComposed();
return _this7;
});
};

Expand Down
61 changes: 24 additions & 37 deletions dist/aurelia-framework.js
Expand Up @@ -77,20 +77,33 @@ export class Plugins {
return this;
}

_addNormalizedPlugin(name, config){
var plugin = { moduleId: name, resourcesRelativeTo: name, config: config || {} };

this.plugin(plugin);

this.aurelia.addPreStartTask(() => {
return System.normalize(name, this.bootstrapperName).then(normalizedName => {
normalizedName = normalizedName.endsWith('.js') || normalizedName.endsWith('.ts')
? normalizedName.substring(0, normalizedName.length - 3) : normalizedName;

plugin.moduleId = normalizedName;
plugin.resourcesRelativeTo = normalizedName;
System.map[name] = normalizedName;
});
});

return this;
}

/**
* Plugs in the default binding language from aurelia-templating-binding.
*
* @method defaultBindingLanguage
* @return {Plugins} Returns the current Plugins instance.
*/
defaultBindingLanguage():Plugins{
this.aurelia.addPreStartTask(() => {
return System.normalize('aurelia-templating-binding', this.bootstrapperName).then(name => {
this.aurelia.use.plugin(name);
});
});

return this;
return this._addNormalizedPlugin('aurelia-templating-binding');
};

/**
Expand All @@ -100,13 +113,7 @@ export class Plugins {
* @return {Plugins} Returns the current Plugins instance.
*/
router():Plugins{
this.aurelia.addPreStartTask(() => {
return System.normalize('aurelia-templating-router', this.bootstrapperName).then(name => {
this.aurelia.use.plugin(name);
});
});

return this;
return this._addNormalizedPlugin('aurelia-templating-router');
}

/**
Expand All @@ -116,13 +123,7 @@ export class Plugins {
* @return {Plugins} Returns the current Plugins instance.
*/
history():Plugins{
this.aurelia.addPreStartTask(() => {
return System.normalize('aurelia-history-browser', this.bootstrapperName).then(name => {
this.aurelia.use.plugin(name);
});
});

return this;
return this._addNormalizedPlugin('aurelia-history-browser');
}

/**
Expand All @@ -132,14 +133,7 @@ export class Plugins {
* @return {Plugins} Returns the current Plugins instance.
*/
defaultResources():Plugins{
this.aurelia.addPreStartTask(() => {
return System.normalize('aurelia-templating-resources', this.bootstrapperName).then(name => {
System.map['aurelia-templating-resources'] = name;
this.aurelia.use.plugin(name);
});
});

return this;
return this._addNormalizedPlugin('aurelia-templating-resources');
}

/**
Expand All @@ -149,14 +143,7 @@ export class Plugins {
* @return {Plugins} Returns the current Plugins instance.
*/
eventAggregator():Plugins{
this.aurelia.addPreStartTask(() => {
return System.normalize('aurelia-event-aggregator', this.bootstrapperName).then(name => {
System.map['aurelia-event-aggregator'] = name;
this.aurelia.use.plugin(name);
});
});

return this;
return this._addNormalizedPlugin('aurelia-event-aggregator');
}

/**
Expand Down

0 comments on commit 25a3529

Please sign in to comment.