@@ -23,7 +23,7 @@ import "package:angular2/src/facade/lang.dart"
2323 isString;
2424import "package:angular2/src/facade/async.dart" show ObservableWrapper;
2525import "package:angular2/src/core/render/api.dart"
26- show Renderer, RootRenderer, RenderComponentType;
26+ show Renderer, RootRenderer, RenderComponentType, RenderDebugInfo ;
2727import "view_ref.dart" show ViewRef_;
2828import "view_type.dart" show ViewType;
2929import "view_utils.dart"
@@ -63,7 +63,6 @@ abstract class AppView<T> {
6363 Injector parentInjector;
6464 AppElement declarationAppElement;
6565 ChangeDetectionStrategy cdMode;
66- List <StaticNodeDebugInfo > staticNodeDebugInfos;
6766 ViewRef_ <T > ref;
6867 List <dynamic > rootNodesOrAppElements;
6968 List <dynamic > allNodes;
@@ -80,18 +79,10 @@ abstract class AppView<T> {
8079 List <dynamic /* dynamic | List < dynamic > */ > projectableNodes;
8180 bool destroyed = false ;
8281 Renderer renderer;
83- DebugContext _currentDebugContext = null ;
8482 bool _hasExternalHostElement;
8583 T context;
86- AppView (
87- this .clazz,
88- this .componentType,
89- this .type,
90- this .viewUtils,
91- this .parentInjector,
92- this .declarationAppElement,
93- this .cdMode,
94- this .staticNodeDebugInfos) {
84+ AppView (this .clazz, this .componentType, this .type, this .viewUtils,
85+ this .parentInjector, this .declarationAppElement, this .cdMode) {
9586 this .ref = new ViewRef_ (this );
9687 if (identical (type, ViewType .COMPONENT ) || identical (type, ViewType .HOST )) {
9788 this .renderer = viewUtils.renderComponent (componentType);
@@ -123,17 +114,7 @@ abstract class AppView<T> {
123114 }
124115 this ._hasExternalHostElement = isPresent (rootSelectorOrNode);
125116 this .projectableNodes = projectableNodes;
126- if (this .debugMode) {
127- this ._resetDebug ();
128- try {
129- return this .createInternal (rootSelectorOrNode);
130- } catch (e, e_stack) {
131- this ._rethrowWithContext (e, e_stack);
132- rethrow ;
133- }
134- } else {
135- return this .createInternal (rootSelectorOrNode);
136- }
117+ return this .createInternal (rootSelectorOrNode);
137118 }
138119
139120 /**
@@ -163,29 +144,19 @@ abstract class AppView<T> {
163144 dynamic selectOrCreateHostElement (
164145 String elementName,
165146 dynamic /* String | dynamic */ rootSelectorOrNode,
166- DebugContext debugCtx ) {
147+ RenderDebugInfo debugInfo ) {
167148 var hostElement;
168149 if (isPresent (rootSelectorOrNode)) {
169150 hostElement =
170- this .renderer.selectRootElement (rootSelectorOrNode, debugCtx );
151+ this .renderer.selectRootElement (rootSelectorOrNode, debugInfo );
171152 } else {
172- hostElement = this .renderer.createElement (null , elementName, debugCtx );
153+ hostElement = this .renderer.createElement (null , elementName, debugInfo );
173154 }
174155 return hostElement;
175156 }
176157
177158 dynamic injectorGet (dynamic token, num nodeIndex, dynamic notFoundResult) {
178- if (this .debugMode) {
179- this ._resetDebug ();
180- try {
181- return this .injectorGetInternal (token, nodeIndex, notFoundResult);
182- } catch (e, e_stack) {
183- this ._rethrowWithContext (e, e_stack);
184- rethrow ;
185- }
186- } else {
187- return this .injectorGetInternal (token, nodeIndex, notFoundResult);
188- }
159+ return this .injectorGetInternal (token, nodeIndex, notFoundResult);
189160 }
190161
191162 /**
@@ -227,21 +198,11 @@ abstract class AppView<T> {
227198 for (var i = 0 ; i < children.length; i++ ) {
228199 children[i]._destroyRecurse ();
229200 }
230- if (this .debugMode) {
231- this ._resetDebug ();
232- try {
233- this ._destroyLocal ();
234- } catch (e, e_stack) {
235- this ._rethrowWithContext (e, e_stack);
236- rethrow ;
237- }
238- } else {
239- this ._destroyLocal ();
240- }
201+ this .destroyLocal ();
241202 this .destroyed = true ;
242203 }
243204
244- _destroyLocal () {
205+ destroyLocal () {
245206 var hostElement = identical (this .type, ViewType .COMPONENT )
246207 ? this .declarationAppElement.nativeElement
247208 : null ;
@@ -268,10 +229,6 @@ abstract class AppView<T> {
268229 * Overwritten by implementations
269230 */
270231 void destroyInternal () {}
271- bool get debugMode {
272- return isPresent (this .staticNodeDebugInfos);
273- }
274-
275232 ChangeDetectorRef get changeDetectorRef {
276233 return this .ref;
277234 }
@@ -317,17 +274,7 @@ abstract class AppView<T> {
317274 if (this .destroyed) {
318275 this .throwDestroyedError ("detectChanges" );
319276 }
320- if (this .debugMode) {
321- this ._resetDebug ();
322- try {
323- this .detectChangesInternal (throwOnChange);
324- } catch (e, e_stack) {
325- this ._rethrowWithContext (e, e_stack);
326- rethrow ;
327- }
328- } else {
329- this .detectChangesInternal (throwOnChange);
330- }
277+ this .detectChangesInternal (throwOnChange);
331278 if (identical (this .cdMode, ChangeDetectionStrategy .CheckOnce ))
332279 this .cdMode = ChangeDetectionStrategy .Checked ;
333280 this .cdState = ChangeDetectorState .CheckedBefore ;
@@ -381,6 +328,74 @@ abstract class AppView<T> {
381328 }
382329 }
383330
331+ Function eventHandler (Function cb) {
332+ return cb;
333+ }
334+
335+ void throwDestroyedError (String details) {
336+ throw new ViewDestroyedException (details);
337+ }
338+ }
339+
340+ class DebugAppView <T > extends AppView <T > {
341+ List <StaticNodeDebugInfo > staticNodeDebugInfos;
342+ DebugContext _currentDebugContext = null ;
343+ DebugAppView (
344+ dynamic clazz,
345+ RenderComponentType componentType,
346+ ViewType type,
347+ ViewUtils viewUtils,
348+ Injector parentInjector,
349+ AppElement declarationAppElement,
350+ ChangeDetectionStrategy cdMode,
351+ this .staticNodeDebugInfos)
352+ : super (clazz, componentType, type, viewUtils, parentInjector,
353+ declarationAppElement, cdMode) {
354+ /* super call moved to initializer */ ;
355+ }
356+ AppElement create (
357+ T context,
358+ List <dynamic /* dynamic | List < dynamic > */ > givenProjectableNodes,
359+ dynamic /* String | dynamic */ rootSelectorOrNode) {
360+ this ._resetDebug ();
361+ try {
362+ return super .create (context, givenProjectableNodes, rootSelectorOrNode);
363+ } catch (e, e_stack) {
364+ this ._rethrowWithContext (e, e_stack);
365+ rethrow ;
366+ }
367+ }
368+
369+ dynamic injectorGet (dynamic token, num nodeIndex, dynamic notFoundResult) {
370+ this ._resetDebug ();
371+ try {
372+ return super .injectorGet (token, nodeIndex, notFoundResult);
373+ } catch (e, e_stack) {
374+ this ._rethrowWithContext (e, e_stack);
375+ rethrow ;
376+ }
377+ }
378+
379+ destroyLocal () {
380+ this ._resetDebug ();
381+ try {
382+ super .destroyLocal ();
383+ } catch (e, e_stack) {
384+ this ._rethrowWithContext (e, e_stack);
385+ rethrow ;
386+ }
387+ }
388+
389+ void detectChanges (bool throwOnChange) {
390+ this ._resetDebug ();
391+ try {
392+ super .detectChanges (throwOnChange);
393+ } catch (e, e_stack) {
394+ this ._rethrowWithContext (e, e_stack);
395+ rethrow ;
396+ }
397+ }
398+
384399 _resetDebug () {
385400 this ._currentDebugContext = null ;
386401 }
@@ -402,23 +417,16 @@ abstract class AppView<T> {
402417 }
403418
404419 Function eventHandler (Function cb) {
405- if (this .debugMode) {
406- return (event) {
407- this ._resetDebug ();
408- try {
409- return cb (event);
410- } catch (e, e_stack) {
411- this ._rethrowWithContext (e, e_stack);
412- rethrow ;
413- }
414- };
415- } else {
416- return cb;
417- }
418- }
419-
420- void throwDestroyedError (String details) {
421- throw new ViewDestroyedException (details);
420+ var superHandler = super .eventHandler (cb);
421+ return (event) {
422+ this ._resetDebug ();
423+ try {
424+ return superHandler (event);
425+ } catch (e, e_stack) {
426+ this ._rethrowWithContext (e, e_stack);
427+ rethrow ;
428+ }
429+ };
422430 }
423431}
424432
0 commit comments