Skip to content

Commit bab4c77

Browse files
fix(all): create a property framework configuration object
This is a BREAKING CHANGE. The Plugins type has been removed and replaced with FrameworkConfiguration. All configuration-style APIs from the Aurelia object have been moved to the FrameworkConfiguration type. Some APIs have been renamed to work better in this context. Anyone that implemented a custom bootstrapper or a plugin, will need to update their configuration code. It should be pretty straight forward.
1 parent 10708ca commit bab4c77

File tree

7 files changed

+588
-551
lines changed

7 files changed

+588
-551
lines changed

build/tasks/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var jsName = paths.packageName + '.js';
1414

1515
gulp.task('build-index', function(){
1616
var importsToAdd = [];
17-
var files = ['plugins.js', 'aurelia.js', 'index.js'].map(function(file){
17+
var files = ['framework-configuration.js', 'aurelia.js', 'index.js'].map(function(file){
1818
return paths.root + file;
1919
});
2020

src/aurelia.js

Lines changed: 22 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import core from 'core-js';
22
import * as TheLogManager from 'aurelia-logging';
33
import {Container} from 'aurelia-dependency-injection';
44
import {Loader} from 'aurelia-loader';
5-
import {join,relativeToFile} from 'aurelia-path';
6-
import {Plugins} from './plugins';
5+
import {FrameworkConfiguration} from './framework-configuration';
76
import {
87
BindingLanguage,
98
ViewEngine,
@@ -45,31 +44,6 @@ function preventActionlessFormSubmit() {
4544
});
4645
}
4746

48-
function loadResources(container, resourcesToLoad, appResources){
49-
var viewEngine = container.get(ViewEngine),
50-
importIds = Object.keys(resourcesToLoad),
51-
names = new Array(importIds.length),
52-
i, ii;
53-
54-
for(i = 0, ii = importIds.length; i < ii; ++i){
55-
names[i] = resourcesToLoad[importIds[i]];
56-
}
57-
58-
return viewEngine.importViewResources(importIds, names, appResources);
59-
}
60-
61-
function runTasks(aurelia, tasks){
62-
let current, next = () => {
63-
if(current = tasks.shift()){
64-
return Promise.resolve(current(aurelia)).then(next);
65-
}
66-
67-
return Promise.resolve();
68-
};
69-
70-
return next();
71-
}
72-
7347
/**
7448
* The framework core that provides the main Aurelia object.
7549
*
@@ -83,127 +57,22 @@ export class Aurelia {
8357
loader:Loader;
8458
container:Container;
8559
resources:ViewResources;
86-
use:Plugins;
60+
use:FrameworkConfiguration;
8761

8862
constructor(loader?:Loader, container?:Container, resources?:ViewResources){
89-
this.hostConfigured = false;
90-
this.host = null;
91-
this.resourcesToLoad = {};
92-
this.preStartTasks = [];
93-
this.postStartTasks = [];
9463
this.loader = loader || new window.AureliaLoader();
9564
this.container = container || new Container();
9665
this.resources = resources || new ViewResources();
97-
this.use = new Plugins(this);
98-
99-
this.withInstance(Aurelia, this);
100-
this.withInstance(Loader, this.loader);
101-
this.withInstance(ViewResources, this.resources);
66+
this.use = new FrameworkConfiguration(this);
67+
this.hostConfigured = false;
68+
this.host = null;
10269

70+
this.use.instance(Aurelia, this);
71+
this.use.instance(Loader, this.loader);
72+
this.use.instance(ViewResources, this.resources);
10373
this.container.makeGlobal();
10474
}
10575

106-
/**
107-
* Adds an existing object to the framework's dependency injection container.
108-
*
109-
* @method withInstance
110-
* @param {Class} type The object type of the dependency that the framework will inject.
111-
* @param {Object} instance The existing instance of the dependency that the framework will inject.
112-
* @return {Aurelia} Returns the current Aurelia instance.
113-
*/
114-
withInstance(type:any, instance:any):Aurelia{
115-
this.container.registerInstance(type, instance);
116-
return this;
117-
}
118-
119-
/**
120-
* Adds a singleton to the framework's dependency injection container.
121-
*
122-
* @method withSingleton
123-
* @param {Class} type The object type of the dependency that the framework will inject.
124-
* @param {Object} implementation The constructor function of the dependency that the framework will inject.
125-
* @return {Aurelia} Returns the current Aurelia instance.
126-
*/
127-
withSingleton(type:any, implementation?:Function):Aurelia{
128-
this.container.registerSingleton(type, implementation);
129-
return this;
130-
}
131-
132-
/**
133-
* Adds a transient to the framework's dependency injection container.
134-
*
135-
* @method withTransient
136-
* @param {Class} type The object type of the dependency that the framework will inject.
137-
* @param {Object} implementation The constructor function of the dependency that the framework will inject.
138-
* @return {Aurelia} Returns the current Aurelia instance.
139-
*/
140-
withTransient(type:any, implementation?:Function):Aurelia{
141-
this.container.registerTransient(type, implementation);
142-
return this;
143-
}
144-
145-
/**
146-
* Adds globally available view resources to be imported into the Aurelia framework.
147-
*
148-
* @method globalizeResources
149-
* @param {Object|Array} resources The relative module id to the resource. (Relative to the plugin's installer.)
150-
* @return {Aurelia} Returns the current Aurelia instance.
151-
*/
152-
globalizeResources(resources:string|string[]):Aurelia{
153-
var toAdd = Array.isArray(resources) ? resources : arguments,
154-
i, ii, resource, path,
155-
resourcesRelativeTo = this.resourcesRelativeTo || '';
156-
157-
for(i = 0, ii = toAdd.length; i < ii; ++i){
158-
resource = toAdd[i];
159-
if(typeof resource != 'string'){
160-
throw new Error(`Invalid resource path [${resource}]. Resources must be specified as relative module IDs.`);
161-
}
162-
163-
path = join(resourcesRelativeTo, resource);
164-
this.resourcesToLoad[path] = this.resourcesToLoad[path];
165-
}
166-
167-
return this;
168-
}
169-
170-
/**
171-
* Renames a global resource that was imported.
172-
*
173-
* @method renameGlobalResource
174-
* @param {String} resourcePath The path to the resource.
175-
* @param {String} newName The new name.
176-
* @return {Aurelia} Returns the current Aurelia instance.
177-
*/
178-
renameGlobalResource(resourcePath:string, newName:string):Aurelia{
179-
this.resourcesToLoad[resourcePath] = newName;
180-
return this;
181-
}
182-
183-
/**
184-
* Adds an async function that runs before the plugins are run.
185-
*
186-
* @method addPreStartTask
187-
* @param {Function} task The function to run before start.
188-
* @return {Aurelia} Returns the current Aurelia instance.
189-
*/
190-
addPreStartTask(task:Function):Aurelia{
191-
this.preStartTasks.push(task);
192-
return this;
193-
}
194-
195-
/**
196-
* Adds an async function that runs after the plugins are run.
197-
*
198-
* @method addPostStartTask
199-
* @param {Function} task The function to run after start.
200-
* @return {Aurelia} Returns the current Aurelia instance.
201-
*/
202-
addPostStartTask(task:Function):Aurelia{
203-
this.postStartTasks.push(task);
204-
return this;
205-
}
206-
20776
/**
20877
* Loads plugins, then resources, and then starts the Aurelia instance.
20978
*
@@ -218,29 +87,23 @@ export class Aurelia {
21887
this.started = true;
21988
logger.info('Aurelia Starting');
22089

221-
preventActionlessFormSubmit();
90+
return this.use.apply().then(() => {
91+
preventActionlessFormSubmit();
22292

223-
return runTasks(this, this.preStartTasks).then(() => {
224-
return this.use._process().then(() => {
225-
if(!this.container.hasHandler(BindingLanguage)){
226-
var message = 'You must configure Aurelia with a BindingLanguage implementation.';
227-
logger.error(message);
228-
throw new Error(message);
229-
}
93+
if(!this.container.hasHandler(BindingLanguage)){
94+
var message = 'You must configure Aurelia with a BindingLanguage implementation.';
95+
logger.error(message);
96+
throw new Error(message);
97+
}
23098

231-
if(!this.container.hasHandler(Animator)){
232-
Animator.configureDefault(this.container);
233-
}
99+
if(!this.container.hasHandler(Animator)){
100+
Animator.configureDefault(this.container);
101+
}
234102

235-
return loadResources(this.container, this.resourcesToLoad, this.resources);
236-
}).then(() => {
237-
return runTasks(this, this.postStartTasks).then(() => {
238-
logger.info('Aurelia Started');
239-
var evt = new window.CustomEvent('aurelia-started', { bubbles: true, cancelable: true });
240-
document.dispatchEvent(evt);
241-
return this;
242-
});
243-
});
103+
logger.info('Aurelia Started');
104+
var evt = new window.CustomEvent('aurelia-started', { bubbles: true, cancelable: true });
105+
document.dispatchEvent(evt);
106+
return this;
244107
});
245108
}
246109

0 commit comments

Comments
 (0)