Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3164bcc

Browse files
committed
Merge pull request #163 from NativeScript/bootstrap-promise
Return Promise form nativeScriptBootstrap
2 parents 7745216 + 0df7771 commit 3164bcc

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

‎ng-sample/app/app.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ import {ModalTest} from "./examples/modal/modal-test";
2727
import {PlatfromDirectivesTest} from "./examples/platform-directives/platform-directives-test";
2828
import {RouterOutletTest} from "./examples/navigation/router-outlet-test";
2929

30-
nativeScriptBootstrap(RendererTest);
30+
nativeScriptBootstrap(RendererTest).then((compRef) => {
31+
console.log("nativeScriptBootstrap resloved: " + compRef);
32+
}).catch((e) => {
33+
console.log("nativeScriptBootstrap error: " + e);
34+
});
3135
//nativeScriptBootstrap(Benchmark);
3236
//nativeScriptBootstrap(ListTest);
3337
//nativeScriptBootstrap(ListTestAsync);

‎src/nativescript-angular/application.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export interface AppOptions {
77

88
export type ProviderArray = Array<Type | Provider | Array<any>>;
99
export function bootstrap(appComponentType: any, componentInjectableBindings?: ProviderArray): Promise<ComponentRef>;
10-
export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: any): void;
10+
export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: any): Promise<ComponentRef>;

‎src/nativescript-angular/application.ts‎

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,41 +78,46 @@ export function bootstrap(appComponentType: any,
7878
return _platform.application(appProviders).bootstrap(appComponentType);
7979
}
8080

81-
export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: AppOptions) {
81+
export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: AppOptions): Promise<ComponentRef> {
8282
if (appOptions && appOptions.cssFile) {
8383
application.cssFile = appOptions.cssFile;
8484
}
85-
application.start({
86-
create: (): Page => {
87-
let page = new Page();
88-
if (appOptions) {
89-
page.actionBarHidden = appOptions.startPageActionBarHidden;
90-
}
9185

92-
let onLoadedHandler = function(args) {
93-
page.off('loaded', onLoadedHandler);
94-
//profiling.stop('application-start');
95-
console.log('Page loaded');
96-
97-
//profiling.start('ng-bootstrap');
98-
console.log('BOOTSTRAPPING...');
99-
bootstrap(appComponentType, customProviders).then((appRef) => {
100-
//profiling.stop('ng-bootstrap');
101-
console.log('ANGULAR BOOTSTRAP DONE.');
102-
}, (err) => {
103-
console.log('ERROR BOOTSTRAPPING ANGULAR');
104-
let errorMessage = err.message + "\n\n" + err.stack;
105-
console.log(errorMessage);
106-
107-
let view = new TextView();
108-
view.text = errorMessage;
109-
page.content = view;
110-
});
86+
return new Promise((resolve, reject) => {
87+
application.start({
88+
create: (): Page => {
89+
let page = new Page();
90+
if (appOptions) {
91+
page.actionBarHidden = appOptions.startPageActionBarHidden;
92+
}
93+
94+
let onLoadedHandler = function(args) {
95+
page.off('loaded', onLoadedHandler);
96+
//profiling.stop('application-start');
97+
console.log('Page loaded');
98+
99+
//profiling.start('ng-bootstrap');
100+
console.log('BOOTSTRAPPING...');
101+
bootstrap(appComponentType, customProviders).then((appRef) => {
102+
//profiling.stop('ng-bootstrap');
103+
console.log('ANGULAR BOOTSTRAP DONE.');
104+
resolve(appRef);
105+
}, (err) => {
106+
console.log('ERROR BOOTSTRAPPING ANGULAR');
107+
let errorMessage = err.message + "\n\n" + err.stack;
108+
console.log(errorMessage);
109+
110+
let view = new TextView();
111+
view.text = errorMessage;
112+
page.content = view;
113+
reject(err);
114+
});
115+
}
116+
117+
page.on('loaded', onLoadedHandler);
118+
119+
return page;
111120
}
112-
113-
page.on('loaded', onLoadedHandler);
114-
115-
return page;
116-
}
117-
});
121+
});
122+
})
118123
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /