@@ -2,8 +2,7 @@ import core from 'core-js';
2
2
import * as TheLogManager from 'aurelia-logging' ;
3
3
import { Container } from 'aurelia-dependency-injection' ;
4
4
import { Loader } from 'aurelia-loader' ;
5
- import { join , relativeToFile } from 'aurelia-path' ;
6
- import { Plugins } from './plugins' ;
5
+ import { FrameworkConfiguration } from './framework-configuration' ;
7
6
import {
8
7
BindingLanguage ,
9
8
ViewEngine ,
@@ -45,31 +44,6 @@ function preventActionlessFormSubmit() {
45
44
} ) ;
46
45
}
47
46
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
-
73
47
/**
74
48
* The framework core that provides the main Aurelia object.
75
49
*
@@ -83,127 +57,22 @@ export class Aurelia {
83
57
loader :Loader ;
84
58
container:Container ;
85
59
resources:ViewResources ;
86
- use:Plugins ;
60
+ use:FrameworkConfiguration ;
87
61
88
62
constructor ( loader ? :Loader , container ? :Container , resources ? :ViewResources ) {
89
- this . hostConfigured = false ;
90
- this . host = null ;
91
- this . resourcesToLoad = { } ;
92
- this . preStartTasks = [ ] ;
93
- this . postStartTasks = [ ] ;
94
63
this . loader = loader || new window . AureliaLoader ( ) ;
95
64
this . container = container || new Container ( ) ;
96
65
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 ;
102
69
70
+ this . use . instance ( Aurelia , this ) ;
71
+ this . use . instance ( Loader , this . loader ) ;
72
+ this . use . instance ( ViewResources , this . resources ) ;
103
73
this . container . makeGlobal ( ) ;
104
74
}
105
75
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
-
207
76
/**
208
77
* Loads plugins, then resources, and then starts the Aurelia instance.
209
78
*
@@ -218,29 +87,23 @@ export class Aurelia {
218
87
this . started = true ;
219
88
logger . info ( 'Aurelia Starting' ) ;
220
89
221
- preventActionlessFormSubmit ( ) ;
90
+ return this . use . apply ( ) . then ( ( ) => {
91
+ preventActionlessFormSubmit ( ) ;
222
92
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
+ }
230
98
231
- if ( ! this . container . hasHandler ( Animator ) ) {
232
- Animator . configureDefault ( this . container ) ;
233
- }
99
+ if ( ! this . container . hasHandler ( Animator ) ) {
100
+ Animator . configureDefault ( this . container ) ;
101
+ }
234
102
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 ;
244
107
} ) ;
245
108
}
246
109
0 commit comments