Skip to content

Commit c3dceba

Browse files
author
Alexander Vakrilov
authored
Merge pull request NativeScript#327 from NativeScript/bootstrap-promise
Don't return promise in nativescriptBootstrap
2 parents 52a8c32 + f811419 commit c3dceba

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

nativescript-angular/application.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ import {rendererLog, rendererError} from "./trace";
99
import {SanitizationService} from '@angular/core/src/security';
1010
import {isPresent, Type, print} from '@angular/core/src/facade/lang';
1111
import {ReflectiveInjector, coreLoadAndBootstrap, createPlatform, EventEmitter,
12-
getPlatform, assertPlatform, ComponentRef, PlatformRef, PLATFORM_DIRECTIVES, PLATFORM_PIPES} from '@angular/core';
13-
import {bind, provide, Provider} from '@angular/core/src/di';
12+
getPlatform, ComponentRef, PLATFORM_DIRECTIVES, PLATFORM_PIPES} from '@angular/core';
13+
import {provide, Provider} from '@angular/core/src/di';
1414

1515
import {RootRenderer, Renderer} from '@angular/core/src/render/api';
1616
import {NativeScriptRootRenderer, NativeScriptRenderer} from './renderer';
1717
import {NativeScriptDomAdapter, NativeScriptElementSchemaRegistry, NativeScriptSanitizationService} from './dom-adapter';
1818
import {ElementSchemaRegistry, XHR, COMPILER_PROVIDERS, CompilerConfig} from '@angular/compiler';
1919
import {FileSystemXHR} from './http/xhr';
20-
import {NSFileSystem} from './file-system/ns-file-system';
21-
import {Parse5DomAdapter} from '@angular/platform-server/src/parse5_adapter';
2220
import {ExceptionHandler} from '@angular/core/src/facade/exception_handler';
2321
import {APPLICATION_COMMON_PROVIDERS} from '@angular/core/src/application_common_providers';
2422
import {PLATFORM_COMMON_PROVIDERS} from '@angular/core/src/platform_common_providers';
@@ -29,7 +27,6 @@ import {Page} from 'ui/page';
2927
import {TextView} from 'ui/text-view';
3028
import application = require('application');
3129
import {topmost, NavigationEntry} from "ui/frame";
32-
import {Observable} from "rxjs";
3330

3431
export type ProviderArray = Array<Type | Provider | any[]>;
3532

@@ -55,9 +52,10 @@ interface BootstrapParams {
5552
customProviders?: ProviderArray,
5653
appOptions?: AppOptions
5754
}
58-
var bootstrapCache: BootstrapParams
5955

60-
var lastBootstrappedApp: WeakRef<ComponentRef<any>>;
56+
let bootstrapCache: BootstrapParams;
57+
let lastBootstrappedApp: WeakRef<ComponentRef<any>>;
58+
6159
export const onBeforeLivesync = new EventEmitter<ComponentRef<any>>();
6260
export const onAfterLivesync = new EventEmitter<ComponentRef<any>>();
6361

@@ -105,24 +103,23 @@ export function bootstrap(appComponentType: any,
105103
NS_COMPILER_PROVIDERS,
106104
provide(ElementSchemaRegistry, { useClass: NativeScriptElementSchemaRegistry }),
107105
provide(XHR, { useClass: FileSystemXHR })
108-
]
106+
];
109107

110-
var appProviders = [defaultAppProviders];
108+
let appProviders = [defaultAppProviders];
111109
if (isPresent(customProviders)) {
112110
appProviders.push(customProviders);
113111
}
114112

115-
var platform = getPlatform();
113+
let platform = getPlatform();
116114
if (!isPresent(platform)) {
117115
platform = createPlatform(ReflectiveInjector.resolveAndCreate(platformProviders));
118116
}
119117

120-
// reflector.reflectionCapabilities = new ReflectionCapabilities();
121-
var appInjector = ReflectiveInjector.resolveAndCreate(appProviders, platform.injector);
118+
let appInjector = ReflectiveInjector.resolveAndCreate(appProviders, platform.injector);
122119
return coreLoadAndBootstrap(appComponentType, appInjector);
123120
}
124121

125-
function createNavigationEntry(params: BootstrapParams, resolve: (comp: ComponentRef<any>) => void, reject: (e: Error) => void, isReboot: boolean) {
122+
function createNavigationEntry(params: BootstrapParams, resolve?: (comp: ComponentRef<any>) => void, reject?: (e: Error) => void, isReboot: boolean = false) {
126123
const navEntry: NavigationEntry = {
127124
create: (): Page => {
128125
let page = new Page();
@@ -141,7 +138,10 @@ function createNavigationEntry(params: BootstrapParams, resolve: (comp: Componen
141138
//profiling.stop('ng-bootstrap');
142139
rendererLog('ANGULAR BOOTSTRAP DONE.');
143140
lastBootstrappedApp = new WeakRef(compRef);
144-
resolve(compRef);
141+
142+
if (resolve) {
143+
resolve(compRef);
144+
}
145145
}, (err) => {
146146
rendererError('ERROR BOOTSTRAPPING ANGULAR');
147147
let errorMessage = err.message + "\n\n" + err.stack;
@@ -150,9 +150,12 @@ function createNavigationEntry(params: BootstrapParams, resolve: (comp: Componen
150150
let view = new TextView();
151151
view.text = errorMessage;
152152
page.content = view;
153-
reject(err);
153+
154+
if (reject) {
155+
reject(err);
156+
}
154157
});
155-
}
158+
};
156159

157160
page.on('loaded', onLoadedHandler);
158161

@@ -168,23 +171,21 @@ function createNavigationEntry(params: BootstrapParams, resolve: (comp: Componen
168171
return navEntry;
169172
}
170173

171-
export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: AppOptions): Promise<ComponentRef<any>> {
174+
export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: AppOptions): void {
172175
bootstrapCache = { appComponentType, customProviders, appOptions };
173176

174177
if (appOptions && appOptions.cssFile) {
175178
application.cssFile = appOptions.cssFile;
176179
}
177180

178-
return new Promise((resolve, reject) => {
179-
const navEntry = createNavigationEntry(bootstrapCache, resolve, reject, false);
180-
application.start(navEntry);
181-
})
181+
const navEntry = createNavigationEntry(bootstrapCache);
182+
application.start(navEntry);
182183
}
183184

184185
// Patch livesync
185186
const _baseLiveSync = global.__onLiveSync;
186187
global.__onLiveSync = function () {
187-
rendererLog("LiveSync Started")
188+
rendererLog("LiveSync Started");
188189
if (bootstrapCache) {
189190
onBeforeLivesync.next(lastBootstrappedApp ? lastBootstrappedApp.get() : null);
190191

@@ -205,6 +206,4 @@ global.__onLiveSync = function () {
205206
else {
206207
_baseLiveSync();
207208
}
208-
}
209-
210-
209+
};

0 commit comments

Comments
 (0)