-
Notifications
You must be signed in to change notification settings - Fork 27.1k
fix(upgrade): make ngUpgrade work with testability API #7603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,10 @@ import { | |
| HostViewFactoryRef, | ||
| Provider, | ||
| Type, | ||
| Testability, | ||
| APPLICATION_COMMON_PROVIDERS | ||
| } from 'angular2/core'; | ||
| import {global} from 'angular2/src/facade/lang'; | ||
| import {ObservableWrapper} from 'angular2/src/facade/async'; | ||
| import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser'; | ||
|
|
||
|
|
@@ -23,6 +25,7 @@ import { | |
| NG1_PARSE, | ||
| NG1_ROOT_SCOPE, | ||
| NG1_SCOPE, | ||
| NG1_TESTABILITY, | ||
| NG2_APP_VIEW_MANAGER, | ||
| NG2_COMPILER, | ||
| NG2_INJECTOR, | ||
|
|
@@ -309,6 +312,7 @@ export class UpgradeAdapter { | |
| var rootScope: angular.IRootScopeService; | ||
| var hostViewFactoryRefMap: HostViewFactoryRefMap = {}; | ||
| var ng1Module = angular.module(this.idPrefix, modules); | ||
| var ng1BootstrapPromise: Promise<any> = null; | ||
| var ng1compilePromise: Promise<any> = null; | ||
| ng1Module.value(NG2_INJECTOR, injector) | ||
| .value(NG2_ZONE, ngZone) | ||
|
|
@@ -331,23 +335,68 @@ export class UpgradeAdapter { | |
| return rootScope = rootScopeDelegate; | ||
| } | ||
| ]); | ||
| } | ||
| ]) | ||
| .run([ | ||
| '$injector', | ||
| '$rootScope', | ||
| (injector: angular.IInjectorService, rootScope: angular.IRootScopeService) => { | ||
| ng1Injector = injector; | ||
| ObservableWrapper.subscribe(ngZone.onMicrotaskEmpty, | ||
| (_) => ngZone.runOutsideAngular(() => rootScope.$apply())); | ||
| ng1compilePromise = | ||
| UpgradeNg1ComponentAdapterBuilder.resolve(this.downgradedComponents, injector); | ||
| provide.decorator(NG1_TESTABILITY, [ | ||
| '$delegate', | ||
| function(testabilityDelegate: angular.ITestabilityService) { | ||
| var ng2Testability: Testability = injector.get(Testability); | ||
|
|
||
| var origonalWhenStable: Function = testabilityDelegate.whenStable; | ||
| var newWhenStable = (callback: Function): void => { | ||
| var whenStableContext: any = this; | ||
| origonalWhenStable.call(this, function() { | ||
| if (ng2Testability.isStable()) { | ||
|
||
| callback.apply(this, arguments); | ||
| } else { | ||
| ng2Testability.whenStable(newWhenStable.bind(whenStableContext, callback)); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| testabilityDelegate.whenStable = newWhenStable; | ||
| return testabilityDelegate; | ||
| } | ||
| ]); | ||
| } | ||
| ]); | ||
|
|
||
| ng1compilePromise = new Promise((resolve, reject) => { | ||
| ng1Module.run([ | ||
| '$injector', | ||
| '$rootScope', | ||
| (injector: angular.IInjectorService, rootScope: angular.IRootScopeService) => { | ||
| ng1Injector = injector; | ||
| ObservableWrapper.subscribe(ngZone.onMicrotaskEmpty, | ||
| (_) => ngZone.runOutsideAngular(() => rootScope.$apply())); | ||
| UpgradeNg1ComponentAdapterBuilder.resolve(this.downgradedComponents, injector) | ||
| .then(resolve, reject); | ||
| } | ||
| ]); | ||
| }); | ||
|
|
||
| // Make sure resumeBootstrap() only exists if the current bootstrap is deferred | ||
| var windowAngular = (<any>global).angular; | ||
| windowAngular.resumeBootstrap = undefined; | ||
|
|
||
| angular.element(element).data(controllerKey(NG2_INJECTOR), injector); | ||
| ngZone.run(() => { angular.bootstrap(element, [this.idPrefix], config); }); | ||
| Promise.all([this.compileNg2Components(compiler, hostViewFactoryRefMap), ng1compilePromise]) | ||
| ng1BootstrapPromise = new Promise((resolve, reject) => { | ||
| if (windowAngular.resumeBootstrap) { | ||
| var originalResumeBootstrap: () => void = windowAngular.resumeBootstrap; | ||
| windowAngular.resumeBootstrap = function() { | ||
| windowAngular.resumeBootstrap = originalResumeBootstrap; | ||
| windowAngular.resumeBootstrap.apply(this, arguments); | ||
| resolve(); | ||
| }; | ||
| } else { | ||
| resolve(); | ||
| } | ||
| }); | ||
|
|
||
| Promise.all([ | ||
| this.compileNg2Components(compiler, hostViewFactoryRefMap), | ||
| ng1BootstrapPromise, | ||
| ng1compilePromise | ||
| ]) | ||
| .then(() => { | ||
| ngZone.run(() => { | ||
| if (rootScopePrototype) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add
resumeBooystrapin the type above ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's there. clang just put it on the same line as
versionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow ! Did clang-format really do that ?
That's pretty unexpected !
(But then again you can't argue with clang-format.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, I didn't put it on that line, so I think it must have been clang