1- define ( [ "exports" , "aurelia-logging" , "aurelia-dependency-injection" , "aurelia-loader" , "aurelia-templating" , "aurelia-event-aggregator " ] , function ( exports , _aureliaLogging , _aureliaDependencyInjection , _aureliaLoader , _aureliaTemplating , _aureliaEventAggregator ) {
1+ define ( [ "exports" , "aurelia-logging" , "aurelia-dependency-injection" , "aurelia-loader" , "aurelia-templating" , "./plugins " ] , function ( exports , _aureliaLogging , _aureliaDependencyInjection , _aureliaLoader , _aureliaTemplating , _plugins ) {
22 "use strict" ;
33
44 var LogManager = _aureliaLogging ;
@@ -8,121 +8,85 @@ define(["exports", "aurelia-logging", "aurelia-dependency-injection", "aurelia-l
88 var ResourceCoordinator = _aureliaTemplating . ResourceCoordinator ;
99 var ViewSlot = _aureliaTemplating . ViewSlot ;
1010 var ResourceRegistry = _aureliaTemplating . ResourceRegistry ;
11- var EventAggregator = _aureliaEventAggregator . EventAggregator ;
12- var includeEventsIn = _aureliaEventAggregator . includeEventsIn ;
11+ var Plugins = _plugins . Plugins ;
1312
1413
1514 var logger = LogManager . getLogger ( "aurelia" ) ;
1615
17- function loadPlugins ( loader , plugins ) {
18- var toLoad = [ ] , i , ii , current ;
19-
20- for ( i = 0 , ii = plugins . length ; i < ii ; ++ i ) {
21- current = plugins [ i ] ;
22- logger . debug ( "Loading plugin " + current . moduleId + "." ) ;
23- toLoad . push ( loader . loadModule ( current . moduleId ) . then ( function ( exportedValue ) {
24- if ( "install" in exportedValue ) {
25- return exportedValue . install ( current . config || { } ) . then ( function ( ) {
26- logger . debug ( "Installed plugin " + current . moduleId + "." ) ;
27- } ) ;
28- } else {
29- logger . debug ( "Loaded plugin " + current . moduleId + "." ) ;
30- }
31- } ) ) ;
16+ var Aurelia = function Aurelia ( loader , container , resources ) {
17+ this . loader = loader || Loader . createDefaultLoader ( ) ;
18+ this . container = container || new Container ( ) ;
19+ this . resources = resources || new ResourceRegistry ( ) ;
20+ this . resourcesToLoad = [ ] ;
21+ this . plugins = new Plugins ( this ) ;
22+
23+ this . withInstance ( Aurelia , this ) ;
24+ this . withInstance ( Loader , this . loader ) ;
25+ this . withInstance ( ResourceRegistry , this . resources ) ;
26+ } ;
27+
28+ Aurelia . prototype . withInstance = function ( type , instance ) {
29+ this . container . registerInstance ( type , instance ) ;
30+ return this ;
31+ } ;
32+
33+ Aurelia . prototype . withSingleton = function ( type , implementation ) {
34+ this . container . registerSingleton ( type , implementation ) ;
35+ return this ;
36+ } ;
37+
38+ Aurelia . prototype . withResources = function ( resources ) {
39+ if ( Array . isArray ( resources ) ) {
40+ this . resourcesToLoad = this . resourcesToLoad . concat ( resources ) ;
41+ } else {
42+ this . resourcesToLoad = this . resourcesToLoad . concat ( Array . prototype . slice . call ( arguments ) ) ;
3243 }
3344
34- return Promise . all ( toLoad ) ;
35- }
36-
37- var Aurelia = ( function ( ) {
38- var Aurelia = function Aurelia ( loader , container , resources ) {
39- this . loader = loader || Loader . createDefaultLoader ( ) ;
40- this . container = container || new Container ( ) ;
41- this . resources = resources || new ResourceRegistry ( ) ;
42- this . resourcesToLoad = [ ] ;
43- this . plugins = [ ] ;
44-
45- this . withInstance ( Aurelia , this ) ;
46- this . withInstance ( Loader , this . loader ) ;
47- this . withInstance ( ResourceRegistry , this . resources ) ;
48- this . withInstance ( EventAggregator , includeEventsIn ( this ) ) ;
49- } ;
50-
51- Aurelia . prototype . withInstance = function ( type , instance ) {
52- this . container . registerInstance ( type , instance ) ;
53- return this ;
54- } ;
55-
56- Aurelia . prototype . withSingleton = function ( type , implementation ) {
57- this . container . registerSingleton ( type , implementation ) ;
58- return this ;
59- } ;
60-
61- Aurelia . prototype . withBindingLanguage = function ( languageType ) {
62- this . container . registerSingleton ( BindingLanguage , languageType ) ;
63- return this ;
64- } ;
65-
66- Aurelia . prototype . withPlugin = function ( moduleId , config ) {
67- this . plugins . push ( { moduleId : moduleId , config : config } ) ;
68- return this ;
69- } ;
70-
71- Aurelia . prototype . withResources = function ( resources ) {
72- if ( Array . isArray ( resources ) ) {
73- this . resourcesToLoad = this . resourcesToLoad . concat ( resources ) ;
74- } else {
75- this . resourcesToLoad = this . resourcesToLoad . concat ( Array . prototype . slice . call ( arguments ) ) ;
76- }
77-
78- return this ;
79- } ;
45+ return this ;
46+ } ;
8047
81- Aurelia . prototype . start = function ( ) {
82- var _this = this ;
83- if ( this . started ) {
84- return ;
85- }
48+ Aurelia . prototype . start = function ( ) {
49+ var _this = this ;
50+ if ( this . started ) {
51+ return ;
52+ }
8653
87- this . started = true ;
88- logger . info ( "Aurelia Starting" ) ;
54+ this . started = true ;
55+ logger . info ( "Aurelia Starting" ) ;
8956
90- if ( ! this . container . hasHandler ( BindingLanguage ) ) {
57+ return this . plugins . process ( ) . then ( function ( ) {
58+ if ( ! _this . container . hasHandler ( BindingLanguage ) ) {
9159 logger . error ( "You must configure Aurelia with a BindingLanguage implementation." ) ;
9260 }
9361
94- return loadPlugins ( this . loader , this . plugins ) . then ( function ( ) {
95- return _this . container . get ( ResourceCoordinator ) . importResources ( _this . resourcesToLoad ) . then ( function ( resources ) {
96- resources . forEach ( function ( x ) {
97- return x . register ( _this . resources ) ;
98- } ) ;
99- logger . info ( "Aurelia Started" ) ;
100- return _this ;
62+ return _this . container . get ( ResourceCoordinator ) . importResources ( _this . resourcesToLoad ) . then ( function ( resources ) {
63+ resources . forEach ( function ( x ) {
64+ return x . register ( _this . resources ) ;
10165 } ) ;
66+ logger . info ( "Aurelia Started" ) ;
67+ return _this ;
10268 } ) ;
103- } ;
104-
105- Aurelia . prototype . setRoot = function ( root , applicationHost ) {
106- var _this2 = this ;
107- if ( ! applicationHost || typeof applicationHost == "string" ) {
108- this . host = document . getElementById ( applicationHost || "applicationHost" ) || document . body ;
109- } else {
110- this . host = applicationHost ;
111- }
112-
113- this . host . aurelia = this ;
69+ } ) ;
70+ } ;
71+
72+ Aurelia . prototype . setRoot = function ( root , applicationHost ) {
73+ var _this2 = this ;
74+ if ( ! applicationHost || typeof applicationHost == "string" ) {
75+ this . host = document . getElementById ( applicationHost || "applicationHost" ) || document . body ;
76+ } else {
77+ this . host = applicationHost ;
78+ }
11479
115- return this . container . get ( ResourceCoordinator ) . loadElement ( root ) . then ( function ( type ) {
116- _this2 . root = type . create ( _this2 . container ) ;
117- var slot = new ViewSlot ( _this2 . host , true ) ;
118- slot . swap ( _this2 . root . view ) ;
119- slot . attached ( ) ;
120- return _this2 ;
121- } ) ;
122- } ;
80+ this . host . aurelia = this ;
12381
124- return Aurelia ;
125- } ) ( ) ;
82+ return this . container . get ( ResourceCoordinator ) . loadElement ( root ) . then ( function ( type ) {
83+ _this2 . root = type . create ( _this2 . container ) ;
84+ var slot = new ViewSlot ( _this2 . host , true ) ;
85+ slot . swap ( _this2 . root . view ) ;
86+ slot . attached ( ) ;
87+ return _this2 ;
88+ } ) ;
89+ } ;
12690
12791 exports . Aurelia = Aurelia ;
12892} ) ;
0 commit comments