angular2-universal
Advanced tools
Comparing version 0.101.1 to 0.101.2
@@ -22,4 +22,4 @@ import { ComponentRef, PlatformRef, ApplicationRef } from '@angular/core'; | ||
bootloader?: Bootloader | any; | ||
ngOnInit?: (config?: ConfigRefs, document?: any) => any | Promise<any>; | ||
ngOnStable?: (config?: ConfigRefs, document?: any) => any | Promise<any>; | ||
ngOnInit?: (config?: ConfigRefs, document?: any) => any | Promise<any> | ConfigRefs; | ||
ngOnStable?: (config?: ConfigRefs, document?: any) => any | Promise<any> | ConfigRefs; | ||
ngOnRendered?: (rendered?: string) => string | any | Promise<any>; | ||
@@ -50,7 +50,7 @@ ngDoCheck?: (config: ConfigRef) => boolean; | ||
_bootstrapAll(Components?: Array<any>, componentProviders?: Array<any>): Promise<Array<any>>; | ||
_applicationAll(config?: AppConfig): Promise<any> | any; | ||
_async(configRefs: ConfigRefs): ConfigRefs | Promise<ConfigRefs> | Promise<Array<ConfigRefs>>; | ||
_preboot(configRefs: ConfigRefs): ConfigRefs | Promise<ConfigRefs>; | ||
_applicationAll(config?: AppConfig): Promise<ConfigRefs>; | ||
_async(configRefs: ConfigRefs): Promise<ConfigRefs>; | ||
_preboot(configRefs: ConfigRefs): Promise<ConfigRefs>; | ||
dispose(): void; | ||
} | ||
export declare function bootloader(config?: BootloaderConfig): Bootloader; |
@@ -91,3 +91,14 @@ "use strict"; | ||
}) | ||
.then(function (configRefs) { return _this._async(configRefs); }) | ||
.then(function (configRefs) { | ||
if ('async' in _this._config) { | ||
if (!_this._config.async) { | ||
return configRefs; | ||
} | ||
var promise = _this._async(configRefs); | ||
return promise; | ||
} | ||
else { | ||
return configRefs; | ||
} | ||
}) | ||
.catch(function (err) { | ||
@@ -109,3 +120,11 @@ console.log('Async Error:', err); | ||
}) | ||
.then(function (configRefs) { return _this._preboot(configRefs); }) | ||
.then(function (configRefs) { | ||
if ('preboot' in _this._config && !_this._config.preboot) { | ||
var promise = _this._preboot(configRefs); | ||
return promise; | ||
} | ||
else { | ||
return configRefs; | ||
} | ||
}) | ||
.catch(function (err) { | ||
@@ -163,6 +182,9 @@ console.log('preboot Error:', err); | ||
// let compRef = Promise.resolve(applicationRef.bootstrap(component)); | ||
return compRef.then(function (componentRef) { return ({ | ||
applicationRef: appInjector.get(core_1.ApplicationRef), | ||
componentRef: componentRef | ||
}); }); | ||
return compRef.then(function (componentRef) { | ||
var configRef = { | ||
applicationRef: appInjector.get(core_1.ApplicationRef), | ||
componentRef: componentRef | ||
}; | ||
return configRef; | ||
}); | ||
}); | ||
@@ -172,82 +194,73 @@ return Promise.all(directives); | ||
Bootloader.prototype._async = function (configRefs) { | ||
if ('async' in this._config) { | ||
if (!this._config.async) { | ||
return configRefs; | ||
} | ||
var ngDoCheck_1 = this._config.ngDoCheck || null; | ||
var maxZoneTurns_1 = Math.max(this._config.maxZoneTurns || 2000, 1); | ||
var apps = configRefs.map(function (config, i) { | ||
// app injector | ||
var ngZone = config.applicationRef.injector.get(core_1.NgZone); | ||
// component injector | ||
var http = config.componentRef.injector.get(http_1.Http, http_1.Http); | ||
var promise = new Promise(function (resolve) { | ||
ngZone.runOutsideAngular(function () { | ||
var checkAmount = 0; | ||
var checkCount = 0; | ||
function checkStable() { | ||
// we setTimeout 10 after the first 20 turns | ||
checkCount++; | ||
if (checkCount === maxZoneTurns_1) { | ||
console.warn('\nWARNING: your application is taking longer than ' + maxZoneTurns_1 + ' Zone turns. \n'); | ||
return resolve(config); | ||
var ngDoCheck = this._config.ngDoCheck || null; | ||
var maxZoneTurns = Math.max(this._config.maxZoneTurns || 2000, 1); | ||
function configMap(config, i) { | ||
// app injector | ||
var ngZone = config.applicationRef.injector.get(core_1.NgZone); | ||
// component injector | ||
var http = config.componentRef.injector.get(http_1.Http, http_1.Http); | ||
var promise = new Promise(function (resolve) { | ||
function outsideNg() { | ||
var checkAmount = 0; | ||
var checkCount = 0; | ||
function checkStable(value) { | ||
// we setTimeout 10 after the first 20 turns | ||
checkCount++; | ||
if (checkCount === maxZoneTurns) { | ||
console.warn('\nWARNING: your application is taking longer than ' + maxZoneTurns + ' Zone turns. \n'); | ||
return resolve(config); | ||
} | ||
if (checkCount === 20) { | ||
checkAmount = 10; | ||
} | ||
function stable() { | ||
if (ngZone.hasPendingMicrotasks) { | ||
return checkStable(value); | ||
} | ||
if (checkCount === 20) { | ||
checkAmount = 10; | ||
if (ngZone.hasPendingMacrotasks) { | ||
return checkStable(value); | ||
} | ||
setTimeout(function () { | ||
if (ngZone.hasPendingMicrotasks) { | ||
return checkStable(); | ||
if (http && http._async > 0) { | ||
return checkStable(value); | ||
} | ||
if (ngZone._isStable && typeof ngDoCheck === 'function') { | ||
var isStable = ngDoCheck(value); | ||
if (isStable === true) { | ||
} | ||
if (ngZone.hasPendingMacrotasks) { | ||
return checkStable(); | ||
else if (typeof isStable !== 'boolean') { | ||
console.warn('\nWARNING: ngDoCheck must return a boolean value of either true or false\n'); | ||
} | ||
if (http && http._async > 0) { | ||
return checkStable(); | ||
else { | ||
return checkStable(value); | ||
} | ||
if (ngZone._isStable && typeof ngDoCheck_1 === 'function') { | ||
var isStable = ngDoCheck_1(config); | ||
if (isStable === true) { | ||
} | ||
else if (typeof isStable !== 'boolean') { | ||
console.warn('\nWARNING: ngDoCheck must return a boolean value of either true or false\n'); | ||
} | ||
else { | ||
return checkStable(); | ||
} | ||
} | ||
if (ngZone._isStable) { | ||
return resolve(config); | ||
} | ||
return checkStable(); | ||
}, checkAmount); | ||
} | ||
if (ngZone._isStable) { | ||
return resolve(value); | ||
} | ||
return checkStable(value); | ||
} | ||
return checkStable(); | ||
}); | ||
}); | ||
return promise; | ||
setTimeout(stable, checkAmount); | ||
} | ||
return checkStable(config); | ||
} | ||
ngZone.runOutsideAngular(outsideNg); | ||
}); | ||
return Promise.all(apps); | ||
return promise; | ||
} | ||
return configRefs; | ||
var apps = configRefs.map(configMap); | ||
return Promise.all(apps); | ||
}; | ||
Bootloader.prototype._preboot = function (configRefs) { | ||
if ('preboot' in this._config) { | ||
if (!this._config.preboot) { | ||
return configRefs; | ||
} | ||
var prebootCode = ng_preboot_1.createPrebootCode(this._config.directives, this._config.preboot); | ||
return prebootCode | ||
.then(function (code) { | ||
// TODO(gdi2290): manage the codegen better after preboot supports multiple appRoot | ||
var lastRef = configRefs[configRefs.length - 1]; | ||
var el = lastRef.componentRef.location.nativeElement; | ||
var script = document_1.parseFragment(code); | ||
var prebootEl = DOM.createElement('div'); | ||
DOM.setInnerHTML(prebootEl, code); | ||
DOM.insertAfter(el, prebootEl); | ||
return configRefs; | ||
}); | ||
} | ||
return configRefs; | ||
var prebootCode = ng_preboot_1.createPrebootCode(this._config.directives, this._config.preboot); | ||
return prebootCode | ||
.then(function (code) { | ||
// TODO(gdi2290): manage the codegen better after preboot supports multiple appRoot | ||
var lastRef = configRefs[configRefs.length - 1]; | ||
var el = lastRef.componentRef.location.nativeElement; | ||
var script = document_1.parseFragment(code); | ||
var prebootEl = DOM.createElement('div'); | ||
DOM.setInnerHTML(prebootEl, code); | ||
DOM.insertAfter(el, prebootEl); | ||
return configRefs; | ||
}); | ||
}; | ||
@@ -254,0 +267,0 @@ Bootloader.prototype.dispose = function () { |
{ | ||
"name": "angular2-universal", | ||
"version": "0.101.1", | ||
"version": "0.101.2", | ||
"description": "Universal (isomorphic) javascript support for Angular2", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/angular/universal", |
@@ -45,4 +45,4 @@ import {DOCUMENT} from '@angular/platform-browser'; | ||
bootloader?: Bootloader | any; | ||
ngOnInit?: (config?: ConfigRefs, document?: any) => any | Promise<any>; | ||
ngOnStable?: (config?: ConfigRefs, document?: any) => any | Promise<any>; | ||
ngOnInit?: (config?: ConfigRefs, document?: any) => any | Promise<any> | ConfigRefs; | ||
ngOnStable?: (config?: ConfigRefs, document?: any) => any | Promise<any> | ConfigRefs; | ||
ngOnRendered?: (rendered?: string) => string | any | Promise<any>; | ||
@@ -133,3 +133,3 @@ ngDoCheck?: (config: ConfigRef) => boolean; | ||
return this._applicationAll(config) | ||
.then((configRefs: ConfigRefs | any) => { | ||
.then((configRefs: ConfigRefs) => { | ||
if ('ngOnInit' in this._config) { | ||
@@ -145,7 +145,17 @@ if (!this._config.ngOnInit) { return configRefs; } | ||
}) | ||
.then((configRefs: ConfigRefs) => this._async(configRefs)) | ||
.then((configRefs: ConfigRefs) => { | ||
if ('async' in this._config) { | ||
if (!this._config.async) { | ||
return configRefs; | ||
} | ||
let promise = this._async(configRefs); | ||
return promise; | ||
} else { | ||
return configRefs; | ||
} | ||
}) | ||
.catch(err => { | ||
console.log('Async Error:', err); | ||
}) | ||
.then((configRefs: any) => { | ||
.then((configRefs: ConfigRefs) => { | ||
if ('ngOnStable' in this._config) { | ||
@@ -161,3 +171,10 @@ if (!this._config.ngOnStable) { return configRefs; } | ||
}) | ||
.then((configRefs: ConfigRefs) => this._preboot(configRefs)) | ||
.then((configRefs: ConfigRefs) => { | ||
if ('preboot' in this._config && !this._config.preboot) { | ||
let promise: any = this._preboot(configRefs); | ||
return promise; | ||
} else { | ||
return configRefs; | ||
} | ||
}) | ||
.catch(err => { | ||
@@ -204,3 +221,3 @@ console.log('preboot Error:', err); | ||
_applicationAll(config: AppConfig = {}): Promise<any> | any { | ||
_applicationAll(config: AppConfig = {}): Promise<ConfigRefs> { | ||
let components: Array<any> = config.directives || this._config.directives; | ||
@@ -216,87 +233,87 @@ let providers: Array<any> = config.providers || this._config.providers; | ||
// let compRef = Promise.resolve(applicationRef.bootstrap(component)); | ||
return compRef.then(componentRef => ({ | ||
applicationRef: appInjector.get(ApplicationRef), | ||
componentRef | ||
})); | ||
return compRef.then(componentRef => { | ||
let configRef: ConfigRef = { | ||
applicationRef: appInjector.get(ApplicationRef), | ||
componentRef | ||
}; | ||
return configRef; | ||
}); | ||
}); | ||
return Promise.all(directives); | ||
return Promise.all<ConfigRef>(directives); | ||
} | ||
_async(configRefs: ConfigRefs): ConfigRefs | Promise<ConfigRefs> | Promise<Array<ConfigRefs>> { | ||
if ('async' in this._config) { | ||
if (!this._config.async) { | ||
return configRefs; | ||
} | ||
let ngDoCheck = this._config.ngDoCheck || null; | ||
let maxZoneTurns = Math.max(this._config.maxZoneTurns || 2000, 1); | ||
_async(configRefs: ConfigRefs): Promise<ConfigRefs> { | ||
let ngDoCheck = this._config.ngDoCheck || null; | ||
let maxZoneTurns = Math.max(this._config.maxZoneTurns || 2000, 1); | ||
function configMap(config: ConfigRef, i: number): Promise<ConfigRef> { | ||
// app injector | ||
let ngZone = config.applicationRef.injector.get(NgZone); | ||
// component injector | ||
let http = config.componentRef.injector.get(Http, Http); | ||
let apps = configRefs.map((config: ConfigRef, i: number) => { | ||
// app injector | ||
let ngZone = config.applicationRef.injector.get(NgZone); | ||
// component injector | ||
let http = config.componentRef.injector.get(Http, Http); | ||
let promise: Promise<ConfigRef> = new Promise(resolve => { | ||
let promise: Promise<ConfigRef> = new Promise(resolve => { | ||
ngZone.runOutsideAngular(() => { | ||
let checkAmount = 0; | ||
let checkCount = 0; | ||
function checkStable() { | ||
// we setTimeout 10 after the first 20 turns | ||
checkCount++; | ||
if (checkCount === maxZoneTurns) { | ||
console.warn('\nWARNING: your application is taking longer than ' + maxZoneTurns + ' Zone turns. \n'); | ||
return resolve(config); | ||
} | ||
if (checkCount === 20) { checkAmount = 10; } | ||
function outsideNg(): void { | ||
let checkAmount: number = 0; | ||
let checkCount: number = 0; | ||
function checkStable(value: ConfigRef): void { | ||
// we setTimeout 10 after the first 20 turns | ||
checkCount++; | ||
if (checkCount === maxZoneTurns) { | ||
console.warn('\nWARNING: your application is taking longer than ' + maxZoneTurns + ' Zone turns. \n'); | ||
return resolve(config); | ||
} | ||
if (checkCount === 20) { checkAmount = 10; } | ||
setTimeout(() => { | ||
if (ngZone.hasPendingMicrotasks) { return checkStable(); } | ||
if (ngZone.hasPendingMacrotasks) { return checkStable(); } | ||
if (http && http._async > 0) { return checkStable(); } | ||
if (ngZone._isStable && typeof ngDoCheck === 'function') { | ||
let isStable = ngDoCheck(config); | ||
if (isStable === true) { | ||
// return resolve(config); | ||
} else if (typeof isStable !== 'boolean') { | ||
console.warn('\nWARNING: ngDoCheck must return a boolean value of either true or false\n'); | ||
} else { | ||
return checkStable(); | ||
} | ||
function stable(): void { | ||
if (ngZone.hasPendingMicrotasks) { return checkStable(value); } | ||
if (ngZone.hasPendingMacrotasks) { return checkStable(value); } | ||
if (http && http._async > 0) { return checkStable(value); } | ||
if (ngZone._isStable && typeof ngDoCheck === 'function') { | ||
let isStable = ngDoCheck(value); | ||
if (isStable === true) { | ||
// return resolve(config); | ||
} else if (typeof isStable !== 'boolean') { | ||
console.warn('\nWARNING: ngDoCheck must return a boolean value of either true or false\n'); | ||
} else { | ||
return checkStable(value); | ||
} | ||
if (ngZone._isStable) { return resolve(config); } | ||
return checkStable(); | ||
}, checkAmount); | ||
} | ||
if (ngZone._isStable) { return resolve(value); } | ||
return checkStable(value); | ||
} | ||
return checkStable(); | ||
}); | ||
}); | ||
return promise; | ||
setTimeout(stable, checkAmount); | ||
} | ||
return checkStable(config); | ||
} | ||
ngZone.runOutsideAngular(outsideNg); | ||
}); | ||
return Promise.all(apps); | ||
return promise; | ||
} | ||
} | ||
return configRefs; | ||
let apps = configRefs.map(configMap); | ||
return Promise.all<ConfigRef>(apps); | ||
} | ||
_preboot(configRefs: ConfigRefs): ConfigRefs | Promise<ConfigRefs> { | ||
if ('preboot' in this._config) { | ||
if (!this._config.preboot) { return configRefs; } | ||
_preboot(configRefs: ConfigRefs): Promise<ConfigRefs> { | ||
let prebootCode = createPrebootCode(this._config.directives, this._config.preboot); | ||
let prebootCode = createPrebootCode(this._config.directives, this._config.preboot); | ||
return prebootCode | ||
.then(code => { | ||
// TODO(gdi2290): manage the codegen better after preboot supports multiple appRoot | ||
let lastRef = configRefs[configRefs.length - 1]; | ||
let el = lastRef.componentRef.location.nativeElement; | ||
let script = parseFragment(code); | ||
let prebootEl = DOM.createElement('div'); | ||
DOM.setInnerHTML(prebootEl, code); | ||
DOM.insertAfter(el, prebootEl); | ||
return configRefs; | ||
}); | ||
} | ||
return configRefs; | ||
return prebootCode | ||
.then(code => { | ||
// TODO(gdi2290): manage the codegen better after preboot supports multiple appRoot | ||
let lastRef = configRefs[configRefs.length - 1]; | ||
let el = lastRef.componentRef.location.nativeElement; | ||
let script = parseFragment(code); | ||
let prebootEl = DOM.createElement('div'); | ||
DOM.setInnerHTML(prebootEl, code); | ||
DOM.insertAfter(el, prebootEl); | ||
return configRefs; | ||
}); | ||
} | ||
@@ -303,0 +320,0 @@ |
Sorry, the diff of this file is not supported yet
540700
8891