2015-04-27 12:49:07 -07:00
|
|
|
import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
|
2015-06-11 19:32:55 +02:00
|
|
|
import {isPresent, isArray} from 'angular2/src/facade/lang';
|
2015-08-14 10:03:45 -07:00
|
|
|
import {RenderDirectiveMetadata} from 'angular2/src/render/api';
|
2015-04-27 12:49:07 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts a [DirectiveMetadata] to a map representation. This creates a copy,
|
|
|
|
|
* that is, subsequent changes to `meta` will not be mirrored in the map.
|
|
|
|
|
*/
|
2015-08-14 10:03:45 -07:00
|
|
|
export function directiveMetadataToMap(meta: RenderDirectiveMetadata): Map<string, any> {
|
2015-04-27 12:49:07 -07:00
|
|
|
return MapWrapper.createFromPairs([
|
|
|
|
|
['id', meta.id],
|
|
|
|
|
['selector', meta.selector],
|
|
|
|
|
['compileChildren', meta.compileChildren],
|
|
|
|
|
['hostProperties', _cloneIfPresent(meta.hostProperties)],
|
2015-06-09 12:33:40 +02:00
|
|
|
['hostListeners', _cloneIfPresent(meta.hostListeners)],
|
2015-05-11 12:31:16 -07:00
|
|
|
['hostActions', _cloneIfPresent(meta.hostActions)],
|
2015-06-09 12:33:40 +02:00
|
|
|
['hostAttributes', _cloneIfPresent(meta.hostAttributes)],
|
2015-04-27 12:49:07 -07:00
|
|
|
['properties', _cloneIfPresent(meta.properties)],
|
|
|
|
|
['readAttributes', _cloneIfPresent(meta.readAttributes)],
|
|
|
|
|
['type', meta.type],
|
2015-06-04 13:45:08 -07:00
|
|
|
['exportAs', meta.exportAs],
|
2015-05-28 17:28:53 -07:00
|
|
|
['callOnDestroy', meta.callOnDestroy],
|
|
|
|
|
['callOnCheck', meta.callOnCheck],
|
|
|
|
|
['callOnInit', meta.callOnInit],
|
|
|
|
|
['callOnChange', meta.callOnChange],
|
|
|
|
|
['callOnAllChangesDone', meta.callOnAllChangesDone],
|
2015-06-12 09:50:30 +02:00
|
|
|
['events', meta.events],
|
|
|
|
|
['changeDetection', meta.changeDetection],
|
2015-05-28 17:28:53 -07:00
|
|
|
['version', 1],
|
2015-04-27 12:49:07 -07:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts a map representation of [DirectiveMetadata] into a
|
|
|
|
|
* [DirectiveMetadata] object. This creates a copy, that is, subsequent changes
|
|
|
|
|
* to `map` will not be mirrored in the [DirectiveMetadata] object.
|
|
|
|
|
*/
|
2015-08-14 10:03:45 -07:00
|
|
|
export function directiveMetadataFromMap(map: Map<string, any>): RenderDirectiveMetadata {
|
|
|
|
|
return new RenderDirectiveMetadata({
|
2015-06-17 16:21:40 -07:00
|
|
|
id:<string>map.get('id'),
|
|
|
|
|
selector:<string>map.get('selector'),
|
|
|
|
|
compileChildren:<boolean>map.get('compileChildren'),
|
|
|
|
|
hostProperties:<Map<string, string>>_cloneIfPresent(map.get('hostProperties')),
|
|
|
|
|
hostListeners:<Map<string, string>>_cloneIfPresent(map.get('hostListeners')),
|
|
|
|
|
hostActions:<Map<string, string>>_cloneIfPresent(map.get('hostActions')),
|
|
|
|
|
hostAttributes:<Map<string, string>>_cloneIfPresent(map.get('hostAttributes')),
|
|
|
|
|
properties:<List<string>>_cloneIfPresent(map.get('properties')),
|
|
|
|
|
readAttributes:<List<string>>_cloneIfPresent(map.get('readAttributes')),
|
|
|
|
|
type:<number>map.get('type'),
|
|
|
|
|
exportAs:<string>map.get('exportAs'),
|
|
|
|
|
callOnDestroy:<boolean>map.get('callOnDestroy'),
|
|
|
|
|
callOnCheck:<boolean>map.get('callOnCheck'),
|
|
|
|
|
callOnChange:<boolean>map.get('callOnChange'),
|
|
|
|
|
callOnInit:<boolean>map.get('callOnInit'),
|
|
|
|
|
callOnAllChangesDone:<boolean>map.get('callOnAllChangesDone'),
|
|
|
|
|
events:<List<string>>_cloneIfPresent(map.get('events')),
|
|
|
|
|
changeDetection:<string>map.get('changeDetection'),
|
2015-04-27 12:49:07 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clones the [List] or [Map] `o` if it is present.
|
|
|
|
|
*/
|
2015-06-09 12:33:40 +02:00
|
|
|
function _cloneIfPresent(o): any {
|
2015-04-27 12:49:07 -07:00
|
|
|
if (!isPresent(o)) return null;
|
2015-06-11 19:32:55 +02:00
|
|
|
return isArray(o) ? ListWrapper.clone(o) : MapWrapper.clone(o);
|
2015-04-27 12:49:07 -07:00
|
|
|
}
|