@@ -24,7 +24,12 @@ import {
2424} from 'angular2/src/facade/lang' ;
2525
2626import { ObservableWrapper } from 'angular2/src/facade/async' ;
27- import { Renderer , RootRenderer , RenderComponentType } from 'angular2/src/core/render/api' ;
27+ import {
28+ Renderer ,
29+ RootRenderer ,
30+ RenderComponentType ,
31+ RenderDebugInfo
32+ } from 'angular2/src/core/render/api' ;
2833import { ViewRef_ } from './view_ref' ;
2934
3035import { ViewType } from './view_type' ;
@@ -78,16 +83,13 @@ export abstract class AppView<T> {
7883
7984 renderer : Renderer ;
8085
81- private _currentDebugContext : DebugContext = null ;
82-
8386 private _hasExternalHostElement : boolean ;
8487
8588 public context : T ;
8689
8790 constructor ( public clazz : any , public componentType : RenderComponentType , public type : ViewType ,
8891 public viewUtils : ViewUtils , public parentInjector : Injector ,
89- public declarationAppElement : AppElement , public cdMode : ChangeDetectionStrategy ,
90- public staticNodeDebugInfos : StaticNodeDebugInfo [ ] ) {
92+ public declarationAppElement : AppElement , public cdMode : ChangeDetectionStrategy ) {
9193 this . ref = new ViewRef_ ( this ) ;
9294 if ( type === ViewType . COMPONENT || type === ViewType . HOST ) {
9395 this . renderer = viewUtils . renderComponent ( componentType ) ;
@@ -115,17 +117,7 @@ export abstract class AppView<T> {
115117 }
116118 this . _hasExternalHostElement = isPresent ( rootSelectorOrNode ) ;
117119 this . projectableNodes = projectableNodes ;
118- if ( this . debugMode ) {
119- this . _resetDebug ( ) ;
120- try {
121- return this . createInternal ( rootSelectorOrNode ) ;
122- } catch ( e ) {
123- this . _rethrowWithContext ( e , e . stack ) ;
124- throw e ;
125- }
126- } else {
127- return this . createInternal ( rootSelectorOrNode ) ;
128- }
120+ return this . createInternal ( rootSelectorOrNode ) ;
129121 }
130122
131123 /**
@@ -150,28 +142,18 @@ export abstract class AppView<T> {
150142 }
151143
152144 selectOrCreateHostElement ( elementName : string , rootSelectorOrNode : string | any ,
153- debugCtx : DebugContext ) : any {
145+ debugInfo : RenderDebugInfo ) : any {
154146 var hostElement ;
155147 if ( isPresent ( rootSelectorOrNode ) ) {
156- hostElement = this . renderer . selectRootElement ( rootSelectorOrNode , debugCtx ) ;
148+ hostElement = this . renderer . selectRootElement ( rootSelectorOrNode , debugInfo ) ;
157149 } else {
158- hostElement = this . renderer . createElement ( null , elementName , debugCtx ) ;
150+ hostElement = this . renderer . createElement ( null , elementName , debugInfo ) ;
159151 }
160152 return hostElement ;
161153 }
162154
163155 injectorGet ( token : any , nodeIndex : number , notFoundResult : any ) : any {
164- if ( this . debugMode ) {
165- this . _resetDebug ( ) ;
166- try {
167- return this . injectorGetInternal ( token , nodeIndex , notFoundResult ) ;
168- } catch ( e ) {
169- this . _rethrowWithContext ( e , e . stack ) ;
170- throw e ;
171- }
172- } else {
173- return this . injectorGetInternal ( token , nodeIndex , notFoundResult ) ;
174- }
156+ return this . injectorGetInternal ( token , nodeIndex , notFoundResult ) ;
175157 }
176158
177159 /**
@@ -210,22 +192,12 @@ export abstract class AppView<T> {
210192 for ( var i = 0 ; i < children . length ; i ++ ) {
211193 children [ i ] . _destroyRecurse ( ) ;
212194 }
213- if ( this . debugMode ) {
214- this . _resetDebug ( ) ;
215- try {
216- this . _destroyLocal ( ) ;
217- } catch ( e ) {
218- this . _rethrowWithContext ( e , e . stack ) ;
219- throw e ;
220- }
221- } else {
222- this . _destroyLocal ( ) ;
223- }
195+ this . destroyLocal ( ) ;
224196
225197 this . destroyed = true ;
226198 }
227199
228- private _destroyLocal ( ) {
200+ destroyLocal ( ) {
229201 var hostElement =
230202 this . type === ViewType . COMPONENT ? this . declarationAppElement . nativeElement : null ;
231203 for ( var i = 0 ; i < this . disposables . length ; i ++ ) {
@@ -250,8 +222,6 @@ export abstract class AppView<T> {
250222 */
251223 destroyInternal ( ) : void { }
252224
253- get debugMode ( ) : boolean { return isPresent ( this . staticNodeDebugInfos ) ; }
254-
255225 get changeDetectorRef ( ) : ChangeDetectorRef { return this . ref ; }
256226
257227 get parent ( ) : AppView < any > {
@@ -293,17 +263,7 @@ export abstract class AppView<T> {
293263 if ( this . destroyed ) {
294264 this . throwDestroyedError ( 'detectChanges' ) ;
295265 }
296- if ( this . debugMode ) {
297- this . _resetDebug ( ) ;
298- try {
299- this . detectChangesInternal ( throwOnChange ) ;
300- } catch ( e ) {
301- this . _rethrowWithContext ( e , e . stack ) ;
302- throw e ;
303- }
304- } else {
305- this . detectChangesInternal ( throwOnChange ) ;
306- }
266+ this . detectChangesInternal ( throwOnChange ) ;
307267 if ( this . cdMode === ChangeDetectionStrategy . CheckOnce )
308268 this . cdMode = ChangeDetectionStrategy . Checked ;
309269
@@ -355,6 +315,61 @@ export abstract class AppView<T> {
355315 }
356316 }
357317
318+ eventHandler ( cb : Function ) : Function { return cb ; }
319+
320+ throwDestroyedError ( details : string ) : void { throw new ViewDestroyedException ( details ) ; }
321+ }
322+
323+ export class DebugAppView < T > extends AppView < T > {
324+ private _currentDebugContext : DebugContext = null ;
325+
326+ constructor ( clazz : any , componentType : RenderComponentType , type : ViewType , viewUtils : ViewUtils ,
327+ parentInjector : Injector , declarationAppElement : AppElement ,
328+ cdMode : ChangeDetectionStrategy , public staticNodeDebugInfos : StaticNodeDebugInfo [ ] ) {
329+ super ( clazz , componentType , type , viewUtils , parentInjector , declarationAppElement , cdMode ) ;
330+ }
331+
332+ create ( context : T , givenProjectableNodes : Array < any | any [ ] > ,
333+ rootSelectorOrNode : string | any ) : AppElement {
334+ this . _resetDebug ( ) ;
335+ try {
336+ return super . create ( context , givenProjectableNodes , rootSelectorOrNode ) ;
337+ } catch ( e ) {
338+ this . _rethrowWithContext ( e , e . stack ) ;
339+ throw e ;
340+ }
341+ }
342+
343+ injectorGet ( token : any , nodeIndex : number , notFoundResult : any ) : any {
344+ this . _resetDebug ( ) ;
345+ try {
346+ return super . injectorGet ( token , nodeIndex , notFoundResult ) ;
347+ } catch ( e ) {
348+ this . _rethrowWithContext ( e , e . stack ) ;
349+ throw e ;
350+ }
351+ }
352+
353+ destroyLocal ( ) {
354+ this . _resetDebug ( ) ;
355+ try {
356+ super . destroyLocal ( ) ;
357+ } catch ( e ) {
358+ this . _rethrowWithContext ( e , e . stack ) ;
359+ throw e ;
360+ }
361+ }
362+
363+ detectChanges ( throwOnChange : boolean ) : void {
364+ this . _resetDebug ( ) ;
365+ try {
366+ super . detectChanges ( throwOnChange ) ;
367+ } catch ( e ) {
368+ this . _rethrowWithContext ( e , e . stack ) ;
369+ throw e ;
370+ }
371+ }
372+
358373 private _resetDebug ( ) { this . _currentDebugContext = null ; }
359374
360375 debug ( nodeIndex : number , rowNum : number , colNum : number ) : DebugContext {
@@ -373,22 +388,17 @@ export abstract class AppView<T> {
373388 }
374389
375390 eventHandler ( cb : Function ) : Function {
376- if ( this . debugMode ) {
377- return ( event ) => {
378- this . _resetDebug ( ) ;
379- try {
380- return cb ( event ) ;
381- } catch ( e ) {
382- this . _rethrowWithContext ( e , e . stack ) ;
383- throw e ;
384- }
385- } ;
386- } else {
387- return cb ;
388- }
391+ var superHandler = super . eventHandler ( cb ) ;
392+ return ( event ) => {
393+ this . _resetDebug ( ) ;
394+ try {
395+ return superHandler ( event ) ;
396+ } catch ( e ) {
397+ this . _rethrowWithContext ( e , e . stack ) ;
398+ throw e ;
399+ }
400+ } ;
389401 }
390-
391- throwDestroyedError ( details : string ) : void { throw new ViewDestroyedException ( details ) ; }
392402}
393403
394404function _findLastRenderNode ( node : any ) : any {
0 commit comments