1- import { isPresent , normalizeBool } from 'angular2/src/core/facade/lang' ;
2- import { HtmlAst } from './html_ast' ;
3- import { ChangeDetectionStrategy } from 'angular2/src/core/change_detection/change_detection' ;
1+ import { isPresent , normalizeBool , serializeEnum , Type } from 'angular2/src/core/facade/lang' ;
2+ import {
3+ ChangeDetectionStrategy ,
4+ changeDetectionStrategyFromJson
5+ } from 'angular2/src/core/change_detection/change_detection' ;
6+ import { ViewEncapsulation , viewEncapsulationFromJson } from 'angular2/src/core/render/api' ;
47
58export class TypeMetadata {
69 id : number ;
7- type : any ;
10+ type : Type ;
811 typeName : string ;
912 typeUrl : string ;
1013 constructor ( { id, type, typeName, typeUrl} :
11- { id ?: number , type ?: string , typeName ?: string , typeUrl ?: string } = { } ) {
14+ { id ?: number , type ?: Type , typeName ?: string , typeUrl ?: string } = { } ) {
1215 this . id = id ;
1316 this . type = type ;
1417 this . typeName = typeName ;
1518 this . typeUrl = typeUrl ;
1619 }
20+
21+ static fromJson ( data : StringMap < string , any > ) : TypeMetadata {
22+ return new TypeMetadata (
23+ { id : data [ 'id' ] , type : data [ 'type' ] , typeName : data [ 'typeName' ] , typeUrl : data [ 'typeUrl' ] } ) ;
24+ }
25+
26+ toJson ( ) : StringMap < string , any > {
27+ return {
28+ // Note: Runtime type can't be serialized...
29+ 'id' : this . id ,
30+ 'typeName' : this . typeName ,
31+ 'typeUrl' : this . typeUrl
32+ } ;
33+ }
1734}
1835
1936export class ChangeDetectionMetadata {
@@ -44,7 +61,7 @@ export class ChangeDetectionMetadata {
4461 callOnChanges ?: boolean ,
4562 callDoCheck ?: boolean ,
4663 callOnInit ?: boolean
47- } ) {
64+ } = { } ) {
4865 this . changeDetection = changeDetection ;
4966 this . properties = properties ;
5067 this . events = events ;
@@ -58,60 +75,102 @@ export class ChangeDetectionMetadata {
5875 this . callDoCheck = callDoCheck ;
5976 this . callOnInit = callOnInit ;
6077 }
78+
79+ static fromJson ( data : StringMap < string , any > ) : ChangeDetectionMetadata {
80+ return new ChangeDetectionMetadata ( {
81+ changeDetection : isPresent ( data [ 'changeDetection' ] ) ?
82+ changeDetectionStrategyFromJson ( data [ 'changeDetection' ] ) :
83+ data [ 'changeDetection' ] ,
84+ properties : data [ 'properties' ] ,
85+ events : data [ 'events' ] ,
86+ hostListeners : data [ 'hostListeners' ] ,
87+ hostProperties : data [ 'hostProperties' ] ,
88+ callAfterContentInit : data [ 'callAfterContentInit' ] ,
89+ callAfterContentChecked : data [ 'callAfterContentChecked' ] ,
90+ callAfterViewInit : data [ 'callAfterViewInit' ] ,
91+ callAfterViewChecked : data [ 'callAfterViewChecked' ] ,
92+ callOnChanges : data [ 'callOnChanges' ] ,
93+ callDoCheck : data [ 'callDoCheck' ] ,
94+ callOnInit : data [ 'callOnInit' ]
95+ } ) ;
96+ }
97+
98+ toJson ( ) : StringMap < string , any > {
99+ return {
100+ 'changeDetection' : isPresent ( this . changeDetection ) ? serializeEnum ( this . changeDetection ) :
101+ this . changeDetection ,
102+ 'properties' : this . properties ,
103+ 'events' : this . events ,
104+ 'hostListeners' : this . hostListeners ,
105+ 'hostProperties' : this . hostProperties ,
106+ 'callAfterContentInit' : this . callAfterContentInit ,
107+ 'callAfterContentChecked' : this . callAfterContentChecked ,
108+ 'callAfterViewInit' : this . callAfterViewInit ,
109+ 'callAfterViewChecked' : this . callAfterViewChecked ,
110+ 'callOnChanges' : this . callOnChanges ,
111+ 'callDoCheck' : this . callDoCheck ,
112+ 'callOnInit' : this . callOnInit
113+ } ;
114+ }
61115}
62116
63117export class TemplateMetadata {
64118 encapsulation : ViewEncapsulation ;
65- nodes : HtmlAst [ ] ;
119+ template : string ;
66120 styles : string [ ] ;
67121 styleAbsUrls : string [ ] ;
68122 ngContentSelectors : string [ ] ;
69- constructor ( { encapsulation, nodes , styles, styleAbsUrls, ngContentSelectors} : {
123+ constructor ( { encapsulation, template , styles, styleAbsUrls, ngContentSelectors} : {
70124 encapsulation ?: ViewEncapsulation ,
71- nodes ?: HtmlAst [ ] ,
125+ template ?: string ,
72126 styles ?: string [ ] ,
73127 styleAbsUrls ?: string [ ] ,
74128 ngContentSelectors ?: string [ ]
75- } ) {
129+ } = { } ) {
76130 this . encapsulation = encapsulation ;
77- this . nodes = nodes ;
131+ this . template = template ;
78132 this . styles = styles ;
79133 this . styleAbsUrls = styleAbsUrls ;
80134 this . ngContentSelectors = ngContentSelectors ;
81135 }
82- }
83136
84- /**
85- * How the template and styles of a view should be encapsulated.
86- */
87- export enum ViewEncapsulation {
88- /**
89- * Emulate scoping of styles by preprocessing the style rules
90- * and adding additional attributes to elements. This is the default.
91- */
92- Emulated ,
93- /**
94- * Uses the native mechanism of the renderer. For the DOM this means creating a ShadowRoot.
95- */
96- Native ,
97- /**
98- * Don't scope the template nor the styles.
99- */
100- None
137+ static fromJson ( data : StringMap < string , any > ) :TemplateMetadata {
138+ return new TemplateMetadata ( {
139+ encapsulation : isPresent ( data [ 'encapsulation' ] ) ?
140+ viewEncapsulationFromJson ( data [ 'encapsulation' ] ) :
141+ data [ 'encapsulation' ] ,
142+ template : data [ 'template' ] ,
143+ styles : data [ 'styles' ] ,
144+ styleAbsUrls : data [ 'styleAbsUrls' ] ,
145+ ngContentSelectors : data [ 'ngContentSelectors' ] ,
146+ } ) ;
147+ }
148+
149+ toJson ( ) : StringMap < string , any > {
150+ return {
151+ 'encapsulation' :
152+ isPresent ( this . encapsulation ) ? serializeEnum ( this . encapsulation ) : this . encapsulation ,
153+ 'template' : this . template ,
154+ 'styles' : this . styles ,
155+ 'styleAbsUrls' : this . styleAbsUrls ,
156+ 'ngContentSelectors' : this . ngContentSelectors ,
157+ } ;
158+ }
101159}
102160
161+
103162export class DirectiveMetadata {
104163 type : TypeMetadata ;
105164 isComponent : boolean ;
106165 selector : string ;
107- hostAttributes : Map < string , string > ;
166+ hostAttributes : StringMap < string , string > ;
108167 changeDetection : ChangeDetectionMetadata ;
109168 template : TemplateMetadata ;
110169 constructor ( { type, isComponent, selector, hostAttributes, changeDetection, template} : {
111170 type ?: TypeMetadata ,
112171 isComponent ?: boolean ,
113172 selector ?: string ,
114- hostAttributes ?: Map < string , string > ,
173+ hostAttributes ?: StringMap < string , string > ,
115174 changeDetection ?: ChangeDetectionMetadata ,
116175 template ?: TemplateMetadata
117176 } = { } ) {
@@ -122,6 +181,32 @@ export class DirectiveMetadata {
122181 this . changeDetection = changeDetection ;
123182 this . template = template ;
124183 }
184+
185+ static fromJson ( data : StringMap < string , any > ) : DirectiveMetadata {
186+ return new DirectiveMetadata ( {
187+ type : isPresent ( data [ 'type' ] ) ? TypeMetadata . fromJson ( data [ 'type' ] ) : data [ 'type' ] ,
188+ isComponent : data [ 'isComponent' ] ,
189+ selector : data [ 'selector' ] ,
190+ hostAttributes : data [ 'hostAttributes' ] ,
191+ changeDetection : isPresent ( data [ 'changeDetection' ] ) ?
192+ ChangeDetectionMetadata . fromJson ( data [ 'changeDetection' ] ) :
193+ data [ 'changeDetection' ] ,
194+ template : isPresent ( data [ 'template' ] ) ? TemplateMetadata . fromJson ( data [ 'template' ] ) :
195+ data [ 'template' ]
196+ } ) ;
197+ }
198+
199+ toJson ( ) : StringMap < string , any > {
200+ return {
201+ 'type' : isPresent ( this . type ) ? this . type . toJson ( ) : this . type ,
202+ 'isComponent' : this . isComponent ,
203+ 'selector' : this . selector ,
204+ 'hostAttributes' : this . hostAttributes ,
205+ 'changeDetection' :
206+ isPresent ( this . changeDetection ) ? this . changeDetection . toJson ( ) : this . changeDetection ,
207+ 'template' : isPresent ( this . template ) ? this . template . toJson ( ) : this . template
208+ } ;
209+ }
125210}
126211
127212export class SourceModule {
0 commit comments