@@ -20,7 +20,6 @@ import {
2020 OpaqueToken ,
2121 ApplicationModule ,
2222 ExceptionHandler ,
23- NgModule ,
2423 platformCore ,
2524 CompilerOptions ,
2625 COMPILER_OPTIONS ,
@@ -29,11 +28,12 @@ import {
2928 Renderer ,
3029 RootRenderer ,
3130 SanitizationService ,
32- PLATFORM_DIRECTIVES ,
3331 PlatformRef ,
32+ ComponentRef ,
33+ NgModule ,
3434 NgModuleFactory ,
3535 NgModuleRef ,
36- Testability ,
36+ EventEmitter ,
3737 createPlatformFactory
3838} from '@angular/core' ;
3939import * as application from "application" ;
@@ -101,7 +101,6 @@ export class NativeScriptModule {
101101
102102export const NS_COMPILER_PROVIDERS = [
103103 COMPILER_PROVIDERS ,
104- //provide(PLATFORM_DIRECTIVES, { useValue: NS_DIRECTIVES, multi: true }),
105104 {
106105 provide : COMPILER_OPTIONS ,
107106 useValue : { providers : [
@@ -112,12 +111,17 @@ export const NS_COMPILER_PROVIDERS = [
112111 }
113112] ;
114113
115- type BootstrapperAction < M > = ( ) => Promise < NgModuleRef < M > > ;
114+ type BootstrapperAction = ( ) => Promise < NgModuleRef < any > > ;
116115
117- let lastBootstrappedApp : WeakRef < NgModuleRef < any > > ;
116+ let lastBootstrappedModule : WeakRef < NgModuleRef < any > > ;
117+ interface BootstrapParams {
118+ appModuleType : Type ,
119+ appOptions ?: AppOptions
120+ }
118121
119- class NativeScriptPlatformRef extends PlatformRef {
122+ let bootstrapCache : BootstrapParams ;
120123
124+ class NativeScriptPlatformRef extends PlatformRef {
121125 constructor ( private platform : PlatformRef , private appOptions ?: AppOptions ) {
122126 super ( ) ;
123127 }
@@ -126,11 +130,41 @@ class NativeScriptPlatformRef extends PlatformRef {
126130 throw new Error ( "Not implemented." ) ;
127131 }
128132
129- bootstrapModule < M > ( moduleType : ConcreteType < M > , compilerOptions : CompilerOptions | CompilerOptions [ ] = [ ] ) : Promise < NgModuleRef < M > > {
130- const mainPageEntry = this . createNavigationEntry ( ( ) => this . platform . bootstrapModule ( moduleType , compilerOptions ) ) ;
133+ private _bootstrapper : BootstrapperAction ;
134+
135+ bootstrapModule < M > ( moduleType : ConcreteType < M > , compilerOptions : CompilerOptions | CompilerOptions [ ] = [ ] ) : Promise < NgModuleRef < M > > {
136+ this . _bootstrapper = ( ) => this . platform . bootstrapModule ( moduleType , compilerOptions ) ;
137+ // Patch livesync
138+ global . __onLiveSyncCore = ( ) => this . livesyncModule ( ) ;
139+
140+ const mainPageEntry = this . createNavigationEntry ( this . _bootstrapper ) ;
141+
131142 application . start ( mainPageEntry ) ;
143+
132144 return null ; //Make the compiler happy
133145 }
146+
147+ livesyncModule ( ) : void {
148+ rendererLog ( "ANGULAR LiveSync Started" ) ;
149+
150+ onBeforeLivesync . next ( lastBootstrappedModule ? lastBootstrappedModule . get ( ) : null ) ;
151+
152+ const mainPageEntry = this . createNavigationEntry (
153+ this . _bootstrapper ,
154+ compRef => onAfterLivesync . next ( compRef ) ,
155+ error => onAfterLivesync . error ( error )
156+ ) ;
157+ mainPageEntry . animated = false ;
158+ mainPageEntry . clearHistory = true ;
159+
160+ const frame = topmost ( ) ;
161+ if ( frame ) {
162+ if ( frame . currentPage && frame . currentPage . modal ) {
163+ frame . currentPage . modal . closeModal ( ) ;
164+ }
165+ frame . navigate ( mainPageEntry ) ;
166+ }
167+ }
134168
135169 registerDisposeListener ( dispose : ( ) => void ) : void {
136170 this . platform . registerDisposeListener ( dispose ) ;
@@ -160,7 +194,7 @@ class NativeScriptPlatformRef extends PlatformRef {
160194 return this . platform . destroyed ;
161195 }
162196
163- private createNavigationEntry < M > ( bootstrapAction : BootstrapperAction < M > , resolve ?: ( comp : NgModuleRef < any > ) => void , reject ?: ( e : Error ) => void , isReboot : boolean = false ) : NavigationEntry {
197+ private createNavigationEntry ( bootstrapAction : BootstrapperAction , resolve ?: ( comp : NgModuleRef < any > ) => void , reject ?: ( e : Error ) => void , isReboot : boolean = false ) : NavigationEntry {
164198 const navEntry : NavigationEntry = {
165199 create : ( ) : Page => {
166200 let page = new Page ( ) ;
@@ -178,7 +212,7 @@ class NativeScriptPlatformRef extends PlatformRef {
178212 bootstrapAction ( ) . then ( ( moduleRef ) => {
179213 //profiling.stop('ng-bootstrap');
180214 rendererLog ( 'ANGULAR BOOTSTRAP DONE.' ) ;
181- lastBootstrappedApp = new WeakRef ( moduleRef ) ;
215+ lastBootstrappedModule = new WeakRef ( moduleRef ) ;
182216
183217 if ( resolve ) {
184218 resolve ( moduleRef ) ;
@@ -212,6 +246,9 @@ class NativeScriptPlatformRef extends PlatformRef {
212246
213247 return navEntry ;
214248 }
249+
250+ liveSyncApp ( ) {
251+ }
215252}
216253
217254var _platformNativeScriptDynamic : PlatformFactory = createPlatformFactory (
@@ -221,3 +258,6 @@ export function platformNativeScriptDynamic(options?: AppOptions, extraProviders
221258 return new NativeScriptPlatformRef ( _platformNativeScriptDynamic ( extraProviders ) , options ) ;
222259}
223260
261+ export const onBeforeLivesync = new EventEmitter < NgModuleRef < any > > ( ) ;
262+ export const onAfterLivesync = new EventEmitter < NgModuleRef < any > > ( ) ;
263+
0 commit comments