angular2-universal-preview
Advanced tools
Comparing version 0.84.3 to 0.85.0
@@ -8,7 +8,9 @@ "use strict"; | ||
function __global(m) { | ||
for (var p in m) | ||
if (!global.hasOwnProperty(p)) | ||
for (var p in m) { | ||
if (!global.hasOwnProperty(p)) { | ||
global[p] = m[p]; | ||
} | ||
} | ||
} | ||
__global(universal); | ||
//# sourceMappingURL=global.js.map |
@@ -17,2 +17,3 @@ import { PlatformRef, ApplicationRef } from 'angular2/core'; | ||
ngOnStable?: Function; | ||
ngOnRendered?: Function; | ||
} | ||
@@ -22,6 +23,6 @@ export declare class Bootloader { | ||
platformRef: any; | ||
appRef: any; | ||
applicationRef: any; | ||
constructor(config: BootloaderConfig); | ||
static create(config: any): Bootloader; | ||
static appRefToString(applicationRefs: any): string; | ||
static applicationRefToString(applicationRefs: any): string; | ||
static parseFragment(document: any): Object; | ||
@@ -28,0 +29,0 @@ static parseDocument(document: any): Object; |
@@ -28,3 +28,3 @@ "use strict"; | ||
this.platformRef = this.platform(); | ||
this.appRef = this.application(); | ||
// this.applicationRef = this.application(); | ||
} | ||
@@ -37,3 +37,3 @@ Bootloader.create = function (config) { | ||
}; | ||
Bootloader.appRefToString = function (applicationRefs) { | ||
Bootloader.applicationRefToString = function (applicationRefs) { | ||
var injector = applicationRefs.injector; | ||
@@ -71,3 +71,3 @@ if (Array.isArray(applicationRefs)) { | ||
if (component) { | ||
return this.appRef.bootstrap(component, providers).then(render_1.waitRouter); | ||
return this.application().bootstrap(component, providers).then(render_1.waitRouter); | ||
} | ||
@@ -80,3 +80,3 @@ else { | ||
return this.bootstrap(Component, componentProviders) | ||
.then(Bootloader.appRefToString); | ||
.then(Bootloader.applicationRefToString); | ||
}; | ||
@@ -93,4 +93,4 @@ Bootloader.prototype.serializeApplication = function (Component, componentProviders) { | ||
} | ||
var document_2 = configRefs[0].appRef.injector.get(common_dom_1.DOCUMENT); | ||
return _this._config.ngOnInit(configRefs, document_2); | ||
var document_2 = configRefs[0].applicationRef.injector.get(common_dom_1.DOCUMENT); | ||
return Promise.resolve(_this._config.ngOnInit(configRefs, document_2)).then(function () { return configRefs; }); | ||
} | ||
@@ -114,16 +114,46 @@ return configRefs; | ||
// app injector | ||
var ngZone = config.appRef.injector.get(core_1.NgZone); | ||
var ngZone = config.applicationRef.injector.get(core_1.NgZone); | ||
// component injector | ||
var http = config.cmpRef.injector.getOptional(http_1.Http); | ||
var http = config.componentRef.injector.getOptional(http_1.Http); | ||
var promise = new Promise(function (resolve) { | ||
if (http && http._async) { | ||
ngZone.onStable.subscribe(function () { | ||
if (http && http._async <= 0) { | ||
resolve(config); | ||
} | ||
}); | ||
} | ||
else { | ||
resolve(config); | ||
} | ||
// let stable = false; | ||
// ngZone.onStable.subscribe(() => { | ||
// console.log('onStable', ngZone.hasPendingMicrotasks, ngZone.hasPendingMacrotasks, ngZone._isStable); | ||
// }); | ||
// ngZone.onMicrotaskEmpty.subscribe(() => { | ||
// console.log('onMicrotaskEmpty', ngZone.hasPendingMicrotasks, ngZone.hasPendingMacrotasks, ngZone._isStable); | ||
// }); | ||
// ngZone.onUnstable.subscribe(() => { | ||
// console.log('onUnstable', ngZone.hasPendingMicrotasks, ngZone.hasPendingMacrotasks, ngZone._isStable); | ||
// }); | ||
// ngZone.onError.subscribe(() => { | ||
// console.log('onError', ngZone.hasPendingMicrotasks, ngZone.hasPendingMacrotasks, ngZone._isStable); | ||
// }); | ||
ngZone.runOutsideAngular(function () { | ||
function checkStable() { | ||
setTimeout(function () { | ||
if (ngZone.hasPendingMicrotasks) { | ||
return checkStable(); | ||
} | ||
if (ngZone.hasPendingMacrotasks) { | ||
return checkStable(); | ||
} | ||
if (ngZone._isStable) { | ||
return resolve(config); | ||
} | ||
return checkStable(); | ||
}); | ||
} | ||
checkStable(); | ||
}); | ||
// if (http && http._async) { | ||
// ngZone.onStable.subscribe(() => { | ||
// console.log('HTTP', http._async); | ||
// if (http && http._async <= 0) { | ||
// console.log('HTTP done'); | ||
// } | ||
// }); | ||
// } else { | ||
// resolve(config); | ||
// } | ||
}); | ||
@@ -137,6 +167,20 @@ return promise; | ||
.catch(function (err) { | ||
console.log('Precache Error:', err); | ||
console.log('Async Error:', err); | ||
throw err; | ||
}) | ||
.then(function (configRefs) { | ||
if ('ngOnStable' in _this._config) { | ||
if (!_this._config.ngOnStable) { | ||
return configRefs; | ||
} | ||
var document_3 = configRefs[0].applicationRef.injector.get(common_dom_1.DOCUMENT); | ||
return Promise.resolve(_this._config.ngOnStable(configRefs, document_3)).then(function () { return configRefs; }); | ||
} | ||
return configRefs; | ||
}) | ||
.catch(function (err) { | ||
console.log('ngOnStable Error:', err); | ||
throw err; | ||
}) | ||
.then(function (configRefs) { | ||
if ('preboot' in _this._config) { | ||
@@ -151,3 +195,3 @@ if (!_this._config.preboot) { | ||
var lastRef = configRefs[configRefs.length - 1]; | ||
var el = lastRef.cmpRef.location.nativeElement; | ||
var el = lastRef.componentRef.location.nativeElement; | ||
var script = document_1.parseFragment(code); | ||
@@ -167,22 +211,27 @@ var prebootEl = dom_adapter_1.DOM.createElement('div'); | ||
.then(function (configRefs) { | ||
if ('ngOnStable' in _this._config) { | ||
if (!_this._config.ngOnStable) { | ||
return configRefs; | ||
} | ||
var document_3 = configRefs[0].appRef.injector.get(common_dom_1.DOCUMENT); | ||
return _this._config.ngOnStable(configRefs, document_3); | ||
var document = configRefs[0].applicationRef.injector.get(common_dom_1.DOCUMENT); | ||
var rendered = Bootloader.serializeDocument(document); | ||
// dispose; | ||
for (var i = 0; i < configRefs.length; i++) { | ||
var config = configRefs[i]; | ||
config.componentRef.dispose(); | ||
config.applicationRef.dispose(); | ||
} | ||
return configRefs; | ||
return rendered; | ||
}) | ||
.catch(function (err) { | ||
console.log('ngOnStable Error:', err); | ||
console.log('Rendering Document Error:', err); | ||
throw err; | ||
}) | ||
.then(function (configRefs) { | ||
var document = configRefs[0].appRef.injector.get(common_dom_1.DOCUMENT); | ||
var rendered = Bootloader.serializeDocument(document); | ||
.then(function (rendered) { | ||
if ('ngOnRendered' in _this._config) { | ||
if (!_this._config.ngOnRendered) { | ||
return rendered; | ||
} | ||
return Promise.resolve(_this._config.ngOnRendered(rendered)).then(function () { return rendered; }); | ||
} | ||
return rendered; | ||
}) | ||
.catch(function (err) { | ||
console.log('Rendering Document Error:', err); | ||
console.log('ngOnRendered Error:', err); | ||
throw err; | ||
@@ -195,3 +244,4 @@ }); | ||
var providers = componentProviders || this._config.componentProviders; | ||
var directives = components.map(function (component) { return _this.appRef.bootstrap(component, providers).then(render_1.waitRouter); }); | ||
// .then(waitRouter)); // fixed by checkStable() | ||
var directives = components.map(function (component) { return _this.application().bootstrap(component, providers); }); | ||
return Promise.all(directives); | ||
@@ -205,5 +255,6 @@ }; | ||
var directives = components.map(function (component) { | ||
var appRef = _this.application(doc); | ||
var compRef = appRef.bootstrap(component, providers).then(render_1.waitRouter); | ||
return compRef.then(function (cmpRef) { return ({ appRef: appRef, cmpRef: cmpRef }); }); | ||
var applicationRef = _this.application(doc); | ||
// .then(waitRouter)); // fixed by checkStable() | ||
var compRef = applicationRef.bootstrap(component, providers); | ||
return compRef.then(function (componentRef) { return ({ applicationRef: applicationRef, componentRef: componentRef }); }); | ||
}); | ||
@@ -213,6 +264,4 @@ return Promise.all(directives); | ||
Bootloader.prototype.dispose = function () { | ||
this.appRef.dispose(); | ||
this.platformRef.dispose(); | ||
this._config = null; | ||
this.appRef = null; | ||
this.platformRef = null; | ||
@@ -219,0 +268,0 @@ }; |
{ | ||
"name": "angular2-universal-preview", | ||
"version": "0.84.3", | ||
"version": "0.85.0", | ||
"description": "Universal (isomorphic) javascript support for Angular2", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/angular/universal", |
@@ -5,4 +5,4 @@ import * as universal from './node/node'; | ||
function __global(m) { | ||
for (var p in m) if (!global.hasOwnProperty(p)) global[p] = m[p]; | ||
for (var p in m) { if (!global.hasOwnProperty(p)) { global[p] = m[p]; } } | ||
} | ||
__global(universal); |
@@ -27,2 +27,3 @@ import {DOCUMENT} from 'angular2/platform/common_dom'; | ||
ngOnStable?: Function; | ||
ngOnRendered?: Function; | ||
} | ||
@@ -52,7 +53,7 @@ | ||
platformRef: any; | ||
appRef: any; | ||
applicationRef: any; | ||
constructor(config: BootloaderConfig) { | ||
(<any>Object).assign(this._config, config || {}); | ||
this.platformRef = this.platform(); | ||
this.appRef = this.application(); | ||
// this.applicationRef = this.application(); | ||
} | ||
@@ -64,3 +65,3 @@ | ||
} | ||
static appRefToString(applicationRefs) { | ||
static applicationRefToString(applicationRefs) { | ||
let injector = applicationRefs.injector; | ||
@@ -101,3 +102,3 @@ if (Array.isArray(applicationRefs)) { | ||
if (component) { | ||
return this.appRef.bootstrap(component, providers).then(waitRouter); | ||
return this.application().bootstrap(component, providers).then(waitRouter); | ||
} else { | ||
@@ -110,3 +111,3 @@ return this._bootstrapAll(component, providers); | ||
return this.bootstrap(Component, componentProviders) | ||
.then(Bootloader.appRefToString); | ||
.then(Bootloader.applicationRefToString); | ||
} | ||
@@ -122,4 +123,4 @@ | ||
if (!this._config.ngOnInit) { return configRefs; } | ||
let document = configRefs[0].appRef.injector.get(DOCUMENT); | ||
return this._config.ngOnInit(configRefs, document); | ||
let document = configRefs[0].applicationRef.injector.get(DOCUMENT); | ||
return Promise.resolve(this._config.ngOnInit(configRefs, document)).then(() => configRefs); | ||
} | ||
@@ -144,16 +145,41 @@ return configRefs; | ||
// app injector | ||
let ngZone = config.appRef.injector.get(NgZone); | ||
let ngZone = config.applicationRef.injector.get(NgZone); | ||
// component injector | ||
let http = config.cmpRef.injector.getOptional(Http); | ||
let http = config.componentRef.injector.getOptional(Http); | ||
let promise = new Promise(resolve => { | ||
if (http && http._async) { | ||
ngZone.onStable.subscribe(() => { | ||
if (http && http._async <= 0) { | ||
resolve(config); | ||
} | ||
}); | ||
} else { | ||
resolve(config); | ||
} | ||
// let stable = false; | ||
// ngZone.onStable.subscribe(() => { | ||
// console.log('onStable', ngZone.hasPendingMicrotasks, ngZone.hasPendingMacrotasks, ngZone._isStable); | ||
// }); | ||
// ngZone.onMicrotaskEmpty.subscribe(() => { | ||
// console.log('onMicrotaskEmpty', ngZone.hasPendingMicrotasks, ngZone.hasPendingMacrotasks, ngZone._isStable); | ||
// }); | ||
// ngZone.onUnstable.subscribe(() => { | ||
// console.log('onUnstable', ngZone.hasPendingMicrotasks, ngZone.hasPendingMacrotasks, ngZone._isStable); | ||
// }); | ||
// ngZone.onError.subscribe(() => { | ||
// console.log('onError', ngZone.hasPendingMicrotasks, ngZone.hasPendingMacrotasks, ngZone._isStable); | ||
// }); | ||
ngZone.runOutsideAngular(() => { | ||
function checkStable() { | ||
setTimeout(() => { | ||
if (ngZone.hasPendingMicrotasks) { return checkStable(); } | ||
if (ngZone.hasPendingMacrotasks) { return checkStable(); } | ||
if (ngZone._isStable) { return resolve(config); } | ||
return checkStable(); | ||
}); | ||
} | ||
checkStable(); | ||
}); | ||
// if (http && http._async) { | ||
// ngZone.onStable.subscribe(() => { | ||
// console.log('HTTP', http._async); | ||
// if (http && http._async <= 0) { | ||
// console.log('HTTP done'); | ||
// } | ||
// }); | ||
// } else { | ||
// resolve(config); | ||
// } | ||
}); | ||
@@ -168,6 +194,18 @@ return promise; | ||
.catch(err => { | ||
console.log('Precache Error:', err); | ||
console.log('Async Error:', err); | ||
throw err; | ||
}) | ||
.then((configRefs: any) => { | ||
if ('ngOnStable' in this._config) { | ||
if (!this._config.ngOnStable) { return configRefs; } | ||
let document = configRefs[0].applicationRef.injector.get(DOCUMENT); | ||
return Promise.resolve(this._config.ngOnStable(configRefs, document)).then(() => configRefs); | ||
} | ||
return configRefs; | ||
}) | ||
.catch(err => { | ||
console.log('ngOnStable Error:', err); | ||
throw err; | ||
}) | ||
.then((configRefs: any) => { | ||
if ('preboot' in this._config) { | ||
@@ -182,3 +220,3 @@ if (!this._config.preboot) { return configRefs; } | ||
let lastRef = configRefs[configRefs.length - 1]; | ||
let el = lastRef.cmpRef.location.nativeElement; | ||
let el = lastRef.componentRef.location.nativeElement; | ||
let script = parseFragment(code); | ||
@@ -198,20 +236,25 @@ let prebootEl = DOM.createElement('div'); | ||
.then((configRefs: any) => { | ||
if ('ngOnStable' in this._config) { | ||
if (!this._config.ngOnStable) { return configRefs; } | ||
let document = configRefs[0].appRef.injector.get(DOCUMENT); | ||
return this._config.ngOnStable(configRefs, document); | ||
let document = configRefs[0].applicationRef.injector.get(DOCUMENT); | ||
let rendered = Bootloader.serializeDocument(document); | ||
// dispose; | ||
for (let i = 0; i < configRefs.length; i++) { | ||
let config = configRefs[i]; | ||
config.componentRef.dispose(); | ||
config.applicationRef.dispose(); | ||
} | ||
return configRefs; | ||
return rendered; | ||
}) | ||
.catch(err => { | ||
console.log('ngOnStable Error:', err); | ||
console.log('Rendering Document Error:', err); | ||
throw err; | ||
}) | ||
.then((configRefs: any) => { | ||
let document = configRefs[0].appRef.injector.get(DOCUMENT); | ||
let rendered = Bootloader.serializeDocument(document); | ||
.then((rendered: any) => { | ||
if ('ngOnRendered' in this._config) { | ||
if (!this._config.ngOnRendered) { return rendered; } | ||
return Promise.resolve(this._config.ngOnRendered(rendered)).then(() => rendered); | ||
} | ||
return rendered; | ||
}) | ||
.catch(err => { | ||
console.log('Rendering Document Error:', err); | ||
console.log('ngOnRendered Error:', err); | ||
throw err; | ||
@@ -226,3 +269,4 @@ }); | ||
let providers = componentProviders || this._config.componentProviders; | ||
let directives = components.map(component => this.appRef.bootstrap(component, providers).then(waitRouter)); | ||
// .then(waitRouter)); // fixed by checkStable() | ||
let directives = components.map(component => this.application().bootstrap(component, providers)); | ||
return Promise.all(directives); | ||
@@ -237,5 +281,6 @@ } | ||
let directives = components.map(component => { | ||
var appRef = this.application(doc); | ||
let compRef = appRef.bootstrap(component, providers).then(waitRouter); | ||
return compRef.then(cmpRef => ({ appRef, cmpRef })); | ||
var applicationRef = this.application(doc); | ||
// .then(waitRouter)); // fixed by checkStable() | ||
let compRef = applicationRef.bootstrap(component, providers); | ||
return compRef.then(componentRef => ({ applicationRef, componentRef })); | ||
}); | ||
@@ -246,6 +291,4 @@ return Promise.all(directives); | ||
dispose(): void { | ||
this.appRef.dispose(); | ||
this.platformRef.dispose(); | ||
this._config = null; | ||
this.appRef = null; | ||
this.platformRef = null; | ||
@@ -252,0 +295,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
338344
6032