@@ -6,7 +6,7 @@ import './polyfills/array';
6
6
import { rendererLog , rendererError } from "./trace" ;
7
7
import { SanitizationService } from '@angular/core/src/security' ;
8
8
import { isPresent , Type , print } from '@angular/core/src/facade/lang' ;
9
- import { ReflectiveInjector , coreLoadAndBootstrap , createPlatform ,
9
+ import { ReflectiveInjector , coreLoadAndBootstrap , createPlatform , EventEmitter ,
10
10
getPlatform , assertPlatform , ComponentRef , PlatformRef , PLATFORM_DIRECTIVES , PLATFORM_PIPES } from '@angular/core' ;
11
11
import { bind , provide , Provider } from '@angular/core/src/di' ;
12
12
@@ -28,6 +28,8 @@ import {NS_DIRECTIVES} from './directives';
28
28
import { Page } from 'ui/page' ;
29
29
import { TextView } from 'ui/text-view' ;
30
30
import application = require( 'application' ) ;
31
+ import { topmost , NavigationEntry } from "ui/frame" ;
32
+ import { Observable } from "rxjs" ;
31
33
32
34
export type ProviderArray = Array < Type | Provider | any [ ] > ;
33
35
@@ -48,9 +50,20 @@ class ConsoleLogger {
48
50
logGroupEnd ( ) { }
49
51
}
50
52
53
+ interface BootstrapParams {
54
+ appComponentType : Type ,
55
+ customProviders ?: ProviderArray ,
56
+ appOptions ?: AppOptions
57
+ }
58
+ var bootstrapCache : BootstrapParams
59
+
60
+ var lastBootstrappedApp : WeakRef < ComponentRef < any > > ;
61
+ export const onBeforeLivesync = new EventEmitter < ComponentRef < any > > ( ) ;
62
+ export const onAfterLivesync = new EventEmitter < ComponentRef < any > > ( ) ;
63
+
51
64
// See: https://github.com/angular/angular/commit/1745366530266d298306b995ecd23dabd8569e28
52
65
export const NS_COMPILER_PROVIDERS : ProviderArray = [
53
- COMPILER_PROVIDERS ,
66
+ COMPILER_PROVIDERS ,
54
67
provide ( CompilerConfig , {
55
68
useFactory : ( platformDirectives : any [ ] , platformPipes : any [ ] ) => {
56
69
return new CompilerConfig ( { platformDirectives, platformPipes } ) ;
@@ -101,7 +114,7 @@ export function bootstrap(appComponentType: any,
101
114
// Http Setup
102
115
// Since HTTP_PROVIDERS can be added with customProviders above, this must come after
103
116
appProviders . push ( [
104
- provide ( XSRFStrategy , { useValue : new NSXSRFStrategy ( ) } ) ,
117
+ provide ( XSRFStrategy , { useValue : new NSXSRFStrategy ( ) } ) ,
105
118
NSFileSystem ,
106
119
provide ( Http , {
107
120
useFactory : ( backend , options , nsFileSystem ) => {
@@ -110,7 +123,7 @@ export function bootstrap(appComponentType: any,
110
123
} )
111
124
] ) ;
112
125
113
- var platform = getPlatform ( ) ;
126
+ var platform = getPlatform ( ) ;
114
127
if ( ! isPresent ( platform ) ) {
115
128
platform = createPlatform ( ReflectiveInjector . resolveAndCreate ( platformProviders ) ) ;
116
129
}
@@ -120,46 +133,89 @@ export function bootstrap(appComponentType: any,
120
133
return coreLoadAndBootstrap ( appComponentType , appInjector ) ;
121
134
}
122
135
136
+ function createNavigationEntry ( params : BootstrapParams , resolve : ( comp : ComponentRef < any > ) => void , reject : ( e : Error ) => void , isReboot : boolean ) {
137
+ const navEntry : NavigationEntry = {
138
+ create : ( ) : Page => {
139
+ let page = new Page ( ) ;
140
+ if ( params . appOptions ) {
141
+ page . actionBarHidden = params . appOptions . startPageActionBarHidden ;
142
+ }
143
+
144
+ let onLoadedHandler = function ( args ) {
145
+ page . off ( 'loaded' , onLoadedHandler ) ;
146
+ //profiling.stop('application-start');
147
+ rendererLog ( 'Page loaded' ) ;
148
+
149
+ //profiling.start('ng-bootstrap');
150
+ rendererLog ( 'BOOTSTRAPPING...' ) ;
151
+ bootstrap ( params . appComponentType , params . customProviders ) . then ( ( compRef ) => {
152
+ //profiling.stop('ng-bootstrap');
153
+ rendererLog ( 'ANGULAR BOOTSTRAP DONE.' ) ;
154
+ lastBootstrappedApp = new WeakRef ( compRef ) ;
155
+ resolve ( compRef ) ;
156
+ } , ( err ) => {
157
+ rendererError ( 'ERROR BOOTSTRAPPING ANGULAR' ) ;
158
+ let errorMessage = err . message + "\n\n" + err . stack ;
159
+ rendererError ( errorMessage ) ;
160
+
161
+ let view = new TextView ( ) ;
162
+ view . text = errorMessage ;
163
+ page . content = view ;
164
+ reject ( err ) ;
165
+ } ) ;
166
+ }
167
+
168
+ page . on ( 'loaded' , onLoadedHandler ) ;
169
+
170
+ return page ;
171
+ }
172
+ } ;
173
+
174
+ if ( isReboot ) {
175
+ navEntry . animated = false ;
176
+ navEntry . clearHistory = true ;
177
+ }
178
+
179
+ return navEntry ;
180
+ }
181
+
123
182
export function nativeScriptBootstrap ( appComponentType : any , customProviders ?: ProviderArray , appOptions ?: AppOptions ) : Promise < ComponentRef < any > > {
183
+ bootstrapCache = { appComponentType, customProviders, appOptions } ;
184
+
124
185
if ( appOptions && appOptions . cssFile ) {
125
186
application . cssFile = appOptions . cssFile ;
126
187
}
127
188
128
189
return new Promise ( ( resolve , reject ) => {
129
- application . start ( {
130
- create : ( ) : Page => {
131
- let page = new Page ( ) ;
132
- if ( appOptions ) {
133
- page . actionBarHidden = appOptions . startPageActionBarHidden ;
134
- }
135
-
136
- let onLoadedHandler = function ( args ) {
137
- page . off ( 'loaded' , onLoadedHandler ) ;
138
- //profiling.stop('application-start');
139
- rendererLog ( 'Page loaded' ) ;
140
-
141
- //profiling.start('ng-bootstrap');
142
- rendererLog ( 'BOOTSTRAPPING...' ) ;
143
- bootstrap ( appComponentType , customProviders ) . then ( ( appRef ) => {
144
- //profiling.stop('ng-bootstrap');
145
- rendererLog ( 'ANGULAR BOOTSTRAP DONE.' ) ;
146
- resolve ( appRef ) ;
147
- } , ( err ) => {
148
- rendererError ( 'ERROR BOOTSTRAPPING ANGULAR' ) ;
149
- let errorMessage = err . message + "\n\n" + err . stack ;
150
- rendererError ( errorMessage ) ;
151
-
152
- let view = new TextView ( ) ;
153
- view . text = errorMessage ;
154
- page . content = view ;
155
- reject ( err ) ;
156
- } ) ;
157
- }
158
-
159
- page . on ( 'loaded' , onLoadedHandler ) ;
160
-
161
- return page ;
162
- }
163
- } ) ;
190
+ const navEntry = createNavigationEntry ( bootstrapCache , resolve , reject , false ) ;
191
+ application . start ( navEntry ) ;
164
192
} )
165
193
}
194
+
195
+ // Patch livesync
196
+ const _baseLiveSync = global . __onLiveSync ;
197
+ global . __onLiveSync = function ( ) {
198
+ rendererLog ( "LiveSync Started" )
199
+ if ( bootstrapCache ) {
200
+ onBeforeLivesync . next ( lastBootstrappedApp ? lastBootstrappedApp . get ( ) : null ) ;
201
+
202
+ const frame = topmost ( ) ;
203
+ const newEntry = createNavigationEntry (
204
+ bootstrapCache ,
205
+ compRef => onAfterLivesync . next ( compRef ) ,
206
+ error => onAfterLivesync . error ( error ) ,
207
+ true ) ;
208
+
209
+ if ( frame ) {
210
+ if ( frame . currentPage && frame . currentPage . modal ) {
211
+ frame . currentPage . modal . closeModal ( ) ;
212
+ }
213
+ frame . navigate ( newEntry ) ;
214
+ }
215
+ }
216
+ else {
217
+ _baseLiveSync ( ) ;
218
+ }
219
+ }
220
+
221
+
0 commit comments