X Tutup
Skip to content

Commit 70586b6

Browse files
harryterkelsenHarry Terkelsen
authored andcommitted
fix(debug): make debug tools take ComponentRef
The debug tools used to take ApplicationRefs, which are the old return type of bootstrap. Now bootstrap returns ComponentRef, so the debug tools should be updated. Closes #4203
1 parent 8f985dd commit 70586b6

File tree

7 files changed

+25
-23
lines changed

7 files changed

+25
-23
lines changed

modules/angular2/src/core/application_common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export function platform(bindings?: Array<Type | Binding | any[]>): PlatformRef
219219
* - `errorReporter`: `function(exception:any, stackTrace:string)` a default error reporter
220220
* for unhandled exceptions.
221221
*
222-
* Returns a `Promise` of {@link ApplicationRef}.
222+
* Returns a `Promise` of {@link ComponentRef}.
223223
*/
224224
export function commonBootstrap(appComponentType: /*Type*/ any,
225225
appBindings: Array<Type | Binding | any[]> = null):

modules/angular2/src/tools/common_tools.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {ApplicationRef, LifeCycle} from 'angular2/angular2';
1+
import {LifeCycle} from 'angular2/angular2';
2+
import {ComponentRef} from 'angular2/src/core/compiler/dynamic_component_loader';
23
import {isPresent, NumberWrapper} from 'angular2/src/core/facade/lang';
34
import {performance, window} from 'angular2/src/core/facade/browser';
45
import {DOM} from 'angular2/src/core/dom/dom_adapter';
@@ -10,7 +11,7 @@ import {DOM} from 'angular2/src/core/dom/dom_adapter';
1011
export class AngularTools {
1112
profiler: AngularProfiler;
1213

13-
constructor(appRef: ApplicationRef) { this.profiler = new AngularProfiler(appRef); }
14+
constructor(ref: ComponentRef) { this.profiler = new AngularProfiler(ref); }
1415
}
1516

1617
/**
@@ -20,7 +21,7 @@ export class AngularTools {
2021
export class AngularProfiler {
2122
lifeCycle: LifeCycle;
2223

23-
constructor(appRef: ApplicationRef) { this.lifeCycle = appRef.injector.get(LifeCycle); }
24+
constructor(ref: ComponentRef) { this.lifeCycle = ref.injector.get(LifeCycle); }
2425

2526
/**
2627
* Exercises change detection in a loop and then prints the average amount of

modules/angular2/src/tools/tools.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
library angular2.src.tools.tools;
22

33
import 'dart:js';
4-
import 'package:angular2/angular2.dart' show ApplicationRef;
4+
import 'package:angular2/src/core/compiler/dynamic_component_loader.dart' show ComponentRef;
55
import 'common_tools.dart' show AngularTools;
66

77
/**
@@ -15,8 +15,8 @@ import 'common_tools.dart' show AngularTools;
1515
* 1. Try the change detection profiler `ng.profiler.timeChangeDetection()`
1616
* then hit Enter.
1717
*/
18-
void enableDebugTools(ApplicationRef appRef) {
19-
final tools = new AngularTools(appRef);
18+
void enableDebugTools(ComponentRef ref) {
19+
final tools = new AngularTools(ref);
2020
context['ng'] = new JsObject.jsify({
2121
'profiler': {
2222
'timeChangeDetection': ([config]) {

modules/angular2/src/tools/tools.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {global} from 'angular2/src/core/facade/lang';
2-
import {ApplicationRef} from 'angular2/angular2';
2+
import {ComponentRef} from 'angular2/src/core/compiler/dynamic_component_loader';
33
import {AngularTools} from './common_tools';
44

55
var context = <any>global;
@@ -15,8 +15,8 @@ var context = <any>global;
1515
* 1. Try the change detection profiler `ng.profiler.timeChangeDetection()`
1616
* then hit Enter.
1717
*/
18-
export function enableDebugTools(appRef: ApplicationRef): void {
19-
context.ng = new AngularTools(appRef);
18+
export function enableDebugTools(ref: ComponentRef): void {
19+
context.ng = new AngularTools(ref);
2020
}
2121

2222
/**
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:angular2/test_lib.dart' show SpyObject;
2-
import 'package:angular2/core.dart'
3-
show ApplicationRef, LifeCycle, Injector, bind;
2+
import 'package:angular2/core.dart' show LifeCycle, Injector, bind;
3+
import 'package:angular2/src/core/compiler/dynamic_component_loader.dart'
4+
show ComponentRef;
45
import 'dart:js';
56

67
@proxy
@@ -9,19 +10,18 @@ class SpyLifeCycle extends SpyObject implements LifeCycle {
910
}
1011

1112
@proxy
12-
class SpyApplicationRef extends SpyObject implements ApplicationRef {
13+
class SpyComponentRef extends SpyObject implements ComponentRef {
1314
Injector injector;
1415

15-
SpyApplicationRef() {
16-
this.injector = Injector.resolveAndCreate([
17-
bind(LifeCycle).toClass(SpyLifeCycle)
18-
]);
16+
SpyComponentRef() {
17+
this.injector =
18+
Injector.resolveAndCreate([bind(LifeCycle).toClass(SpyLifeCycle)]);
1919
}
2020

2121
noSuchMethod(m) => super.noSuchMethod(m);
2222
}
2323

2424
void callNgProfilerTimeChangeDetection([config]) {
25-
context['ng']['profiler'].callMethod('timeChangeDetection',
26-
config != null ? [config] : []);
25+
context['ng']['profiler']
26+
.callMethod('timeChangeDetection', config != null ? [config] : []);
2727
}

modules/angular2/test/tools/spies.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {SpyObject} from 'angular2/test_lib';
2-
import {ApplicationRef, LifeCycle, Injector, bind} from 'angular2/angular2';
2+
import {LifeCycle, Injector, bind} from 'angular2/angular2';
3+
import {ComponentRef} from 'angular2/src/core/compiler/dynamic_component_loader';
34
import {global} from 'angular2/src/core/facade/lang';
45

5-
export class SpyApplicationRef extends SpyObject {
6+
export class SpyComponentRef extends SpyObject {
67
injector;
78
constructor() {
89
super();

modules/angular2/test/tools/tools_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
} from 'angular2/test_lib';
1212

1313
import {enableDebugTools, disableDebugTools} from 'angular2/tools';
14-
import {SpyApplicationRef, callNgProfilerTimeChangeDetection} from './spies';
14+
import {SpyComponentRef, callNgProfilerTimeChangeDetection} from './spies';
1515

1616
export function main() {
1717
describe('profiler', () => {
18-
beforeEach(() => { enableDebugTools((<any>new SpyApplicationRef())); });
18+
beforeEach(() => { enableDebugTools((<any>new SpyComponentRef())); });
1919

2020
afterEach(() => { disableDebugTools(); });
2121

0 commit comments

Comments
 (0)
X Tutup