11define ( [ "exports" , "aurelia-logging" , "aurelia-dependency-injection" , "aurelia-loader" , "aurelia-templating" , "./plugins" ] , function ( exports , _aureliaLogging , _aureliaDependencyInjection , _aureliaLoader , _aureliaTemplating , _plugins ) {
22 "use strict" ;
33
4+ var _prototypeProperties = function ( child , staticProps , instanceProps ) {
5+ if ( staticProps ) Object . defineProperties ( child , staticProps ) ;
6+ if ( instanceProps ) Object . defineProperties ( child . prototype , instanceProps ) ;
7+ } ;
8+
49 var LogManager = _aureliaLogging ;
510 var Container = _aureliaDependencyInjection . Container ;
611 var Loader = _aureliaLoader . Loader ;
@@ -12,88 +17,132 @@ define(["exports", "aurelia-logging", "aurelia-dependency-injection", "aurelia-l
1217 var Plugins = _plugins . Plugins ;
1318
1419
15- var logger = LogManager . getLogger ( "aurelia" ) ;
16-
17- var Aurelia = function Aurelia ( loader , container , resources ) {
18- this . loader = loader || Loader . createDefaultLoader ( ) ;
19- this . container = container || new Container ( ) ;
20- this . resources = resources || new ResourceRegistry ( ) ;
21- this . resourcesToLoad = [ ] ;
22- this . plugins = new Plugins ( this ) ;
20+ var logger = LogManager . getLogger ( "aurelia" ) ,
21+ slice = Array . prototype . slice ;
2322
24- this . withInstance ( Aurelia , this ) ;
25- this . withInstance ( Loader , this . loader ) ;
26- this . withInstance ( ResourceRegistry , this . resources ) ;
27- } ;
28-
29- Aurelia . prototype . withInstance = function ( type , instance ) {
30- this . container . registerInstance ( type , instance ) ;
31- return this ;
32- } ;
23+ function loadResources ( container , resourcesToLoad , appResources ) {
24+ var resourceCoordinator = container . get ( ResourceCoordinator ) , current ;
3325
34- Aurelia . prototype . withSingleton = function ( type , implementation ) {
35- this . container . registerSingleton ( type , implementation ) ;
36- return this ;
37- } ;
26+ function next ( ) {
27+ if ( current = resourcesToLoad . shift ( ) ) {
28+ return resourceCoordinator . importResources ( current ) . then ( function ( resources ) {
29+ resources . forEach ( function ( x ) {
30+ return x . register ( appResources ) ;
31+ } ) ;
32+ return next ( ) ;
33+ } ) ;
34+ }
3835
39- Aurelia . prototype . withResources = function ( resources ) {
40- if ( Array . isArray ( resources ) ) {
41- this . resourcesToLoad = this . resourcesToLoad . concat ( resources ) ;
42- } else {
43- this . resourcesToLoad = this . resourcesToLoad . concat ( Array . prototype . slice . call ( arguments ) ) ;
36+ return Promise . resolve ( ) ;
4437 }
4538
46- return this ;
47- } ;
39+ return next ( ) ;
40+ }
4841
49- Aurelia . prototype . start = function ( ) {
50- var _this = this ;
51- if ( this . started ) {
52- return ;
53- }
42+ var Aurelia = ( function ( ) {
43+ function Aurelia ( loader , container , resources ) {
44+ this . loader = loader || Loader . createDefaultLoader ( ) ;
45+ this . container = container || new Container ( ) ;
46+ this . resources = resources || new ResourceRegistry ( ) ;
47+ this . resourcesToLoad = [ ] ;
48+ this . plugins = new Plugins ( this ) ;
5449
55- this . started = true ;
56- logger . info ( "Aurelia Starting" ) ;
50+ this . withInstance ( Aurelia , this ) ;
51+ this . withInstance ( Loader , this . loader ) ;
52+ this . withInstance ( ResourceRegistry , this . resources ) ;
53+ }
5754
58- return this . plugins . process ( ) . then ( function ( ) {
59- if ( ! _this . container . hasHandler ( BindingLanguage ) ) {
60- logger . error ( "You must configure Aurelia with a BindingLanguage implementation." ) ;
55+ _prototypeProperties ( Aurelia , null , {
56+ withInstance : {
57+ value : function ( type , instance ) {
58+ this . container . registerInstance ( type , instance ) ;
59+ return this ;
60+ } ,
61+ writable : true ,
62+ enumerable : true ,
63+ configurable : true
64+ } ,
65+ withSingleton : {
66+ value : function ( type , implementation ) {
67+ this . container . registerSingleton ( type , implementation ) ;
68+ return this ;
69+ } ,
70+ writable : true ,
71+ enumerable : true ,
72+ configurable : true
73+ } ,
74+ withResources : {
75+ value : function ( resources ) {
76+ if ( Array . isArray ( resources ) ) {
77+ this . resourcesToLoad . push ( resources ) ;
78+ } else {
79+ this . resourcesToLoad . push ( slice . call ( arguments ) ) ;
80+ }
81+
82+ return this ;
83+ } ,
84+ writable : true ,
85+ enumerable : true ,
86+ configurable : true
87+ } ,
88+ start : {
89+ value : function ( ) {
90+ var _this = this ;
91+ if ( this . started ) {
92+ return ;
93+ }
94+
95+ this . started = true ;
96+ logger . info ( "Aurelia Starting" ) ;
97+
98+ return this . plugins . process ( ) . then ( function ( ) {
99+ if ( ! _this . container . hasHandler ( BindingLanguage ) ) {
100+ logger . error ( "You must configure Aurelia with a BindingLanguage implementation." ) ;
101+ }
102+
103+ return loadResources ( _this . container , _this . resourcesToLoad , _this . resources ) . then ( function ( ) {
104+ logger . info ( "Aurelia Started" ) ;
105+ return _this ;
106+ } ) ;
107+ } ) ;
108+ } ,
109+ writable : true ,
110+ enumerable : true ,
111+ configurable : true
112+ } ,
113+ setRoot : {
114+ value : function ( root , applicationHost ) {
115+ var _this2 = this ;
116+ var compositionEngine , instruction = { } ;
117+
118+ if ( ! applicationHost || typeof applicationHost == "string" ) {
119+ this . host = document . getElementById ( applicationHost || "applicationHost" ) || document . body ;
120+ } else {
121+ this . host = applicationHost ;
122+ }
123+
124+ this . host . aurelia = this ;
125+ this . container . registerInstance ( Element , this . host ) ;
126+
127+ compositionEngine = this . container . get ( CompositionEngine ) ;
128+ instruction . viewModel = root ;
129+ instruction . viewSlot = new ViewSlot ( this . host , true ) ;
130+ instruction . container = instruction . childContainer = this . container ;
131+
132+ return compositionEngine . compose ( instruction ) . then ( function ( root ) {
133+ _this2 . root = root ;
134+ instruction . viewSlot . attached ( ) ;
135+ return _this2 ;
136+ } ) ;
137+ } ,
138+ writable : true ,
139+ enumerable : true ,
140+ configurable : true
61141 }
62-
63- return _this . container . get ( ResourceCoordinator ) . importResources ( _this . resourcesToLoad ) . then ( function ( resources ) {
64- resources . forEach ( function ( x ) {
65- return x . register ( _this . resources ) ;
66- } ) ;
67- logger . info ( "Aurelia Started" ) ;
68- return _this ;
69- } ) ;
70142 } ) ;
71- } ;
72-
73- Aurelia . prototype . setRoot = function ( root , applicationHost ) {
74- var _this2 = this ;
75- var compositionEngine , instruction = { } ;
76143
77- if ( ! applicationHost || typeof applicationHost == "string" ) {
78- this . host = document . getElementById ( applicationHost || "applicationHost" ) || document . body ;
79- } else {
80- this . host = applicationHost ;
81- }
82-
83- this . host . aurelia = this ;
84- this . container . registerInstance ( Element , this . host ) ;
85-
86- compositionEngine = this . container . get ( CompositionEngine ) ;
87- instruction . viewModel = root ;
88- instruction . viewSlot = new ViewSlot ( this . host , true ) ;
89- instruction . container = instruction . childContainer = this . container ;
90-
91- return compositionEngine . compose ( instruction ) . then ( function ( root ) {
92- _this2 . root = root ;
93- instruction . viewSlot . attached ( ) ;
94- return _this2 ;
95- } ) ;
96- } ;
144+ return Aurelia ;
145+ } ) ( ) ;
97146
98147 exports . Aurelia = Aurelia ;
99148} ) ;
0 commit comments