1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { getDebugNode } from '@angular/core';
|
9 | import { scheduleMicroTask } from './facade/lang';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export var ComponentFixture = (function () {
|
16 | function ComponentFixture(componentRef, ngZone, _autoDetect) {
|
17 | var _this = this;
|
18 | this.componentRef = componentRef;
|
19 | this.ngZone = ngZone;
|
20 | this._autoDetect = _autoDetect;
|
21 | this._isStable = true;
|
22 | this._isDestroyed = false;
|
23 | this._promise = null;
|
24 | this._onUnstableSubscription = null;
|
25 | this._onStableSubscription = null;
|
26 | this._onMicrotaskEmptySubscription = null;
|
27 | this._onErrorSubscription = null;
|
28 | this.changeDetectorRef = componentRef.changeDetectorRef;
|
29 | this.elementRef = componentRef.location;
|
30 | this.debugElement = getDebugNode(this.elementRef.nativeElement);
|
31 | this.componentInstance = componentRef.instance;
|
32 | this.nativeElement = this.elementRef.nativeElement;
|
33 | this.componentRef = componentRef;
|
34 | this.ngZone = ngZone;
|
35 | if (ngZone != null) {
|
36 | this._onUnstableSubscription =
|
37 | ngZone.onUnstable.subscribe({ next: function () { _this._isStable = false; } });
|
38 | this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
|
39 | next: function () {
|
40 | if (_this._autoDetect) {
|
41 |
|
42 |
|
43 | _this.detectChanges(true);
|
44 | }
|
45 | }
|
46 | });
|
47 | this._onStableSubscription = ngZone.onStable.subscribe({
|
48 | next: function () {
|
49 | _this._isStable = true;
|
50 |
|
51 | if (_this._promise !== null) {
|
52 |
|
53 |
|
54 |
|
55 | scheduleMicroTask(function () {
|
56 | if (!_this.ngZone.hasPendingMacrotasks) {
|
57 | if (_this._promise !== null) {
|
58 | _this._resolve(true);
|
59 | _this._resolve = null;
|
60 | _this._promise = null;
|
61 | }
|
62 | }
|
63 | });
|
64 | }
|
65 | }
|
66 | });
|
67 | this._onErrorSubscription =
|
68 | ngZone.onError.subscribe({ next: function (error) { throw error; } });
|
69 | }
|
70 | }
|
71 | ComponentFixture.prototype._tick = function (checkNoChanges) {
|
72 | this.changeDetectorRef.detectChanges();
|
73 | if (checkNoChanges) {
|
74 | this.checkNoChanges();
|
75 | }
|
76 | };
|
77 | |
78 |
|
79 |
|
80 | ComponentFixture.prototype.detectChanges = function (checkNoChanges) {
|
81 | var _this = this;
|
82 | if (checkNoChanges === void 0) { checkNoChanges = true; }
|
83 | if (this.ngZone != null) {
|
84 |
|
85 |
|
86 | this.ngZone.run(function () { _this._tick(checkNoChanges); });
|
87 | }
|
88 | else {
|
89 |
|
90 | this._tick(checkNoChanges);
|
91 | }
|
92 | };
|
93 | |
94 |
|
95 |
|
96 | ComponentFixture.prototype.checkNoChanges = function () { this.changeDetectorRef.checkNoChanges(); };
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 | ComponentFixture.prototype.autoDetectChanges = function (autoDetect) {
|
103 | if (autoDetect === void 0) { autoDetect = true; }
|
104 | if (this.ngZone == null) {
|
105 | throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set');
|
106 | }
|
107 | this._autoDetect = autoDetect;
|
108 | this.detectChanges();
|
109 | };
|
110 | |
111 |
|
112 |
|
113 |
|
114 | ComponentFixture.prototype.isStable = function () { return this._isStable && !this.ngZone.hasPendingMacrotasks; };
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | ComponentFixture.prototype.whenStable = function () {
|
122 | var _this = this;
|
123 | if (this.isStable()) {
|
124 | return Promise.resolve(false);
|
125 | }
|
126 | else if (this._promise !== null) {
|
127 | return this._promise;
|
128 | }
|
129 | else {
|
130 | this._promise = new Promise(function (res) { _this._resolve = res; });
|
131 | return this._promise;
|
132 | }
|
133 | };
|
134 | |
135 |
|
136 |
|
137 | ComponentFixture.prototype.destroy = function () {
|
138 | if (!this._isDestroyed) {
|
139 | this.componentRef.destroy();
|
140 | if (this._onUnstableSubscription != null) {
|
141 | this._onUnstableSubscription.unsubscribe();
|
142 | this._onUnstableSubscription = null;
|
143 | }
|
144 | if (this._onStableSubscription != null) {
|
145 | this._onStableSubscription.unsubscribe();
|
146 | this._onStableSubscription = null;
|
147 | }
|
148 | if (this._onMicrotaskEmptySubscription != null) {
|
149 | this._onMicrotaskEmptySubscription.unsubscribe();
|
150 | this._onMicrotaskEmptySubscription = null;
|
151 | }
|
152 | if (this._onErrorSubscription != null) {
|
153 | this._onErrorSubscription.unsubscribe();
|
154 | this._onErrorSubscription = null;
|
155 | }
|
156 | this._isDestroyed = true;
|
157 | }
|
158 | };
|
159 | return ComponentFixture;
|
160 | }());
|
161 |
|
\ | No newline at end of file |