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-04-27 12:49:07 -07:00
|
|
|
import {DirectiveMetadata} from 'angular2/src/render/api';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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-05-18 11:57:20 -07:00
|
|
|
export function directiveMetadataToMap(meta: DirectiveMetadata): 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-05-18 11:57:20 -07:00
|
|
|
export function directiveMetadataFromMap(map: Map<string, any>): DirectiveMetadata {
|
2015-04-27 12:49:07 -07:00
|
|
|
return new DirectiveMetadata({
|
2015-05-18 11:57:20 -07:00
|
|
|
id:<string>MapWrapper.get(map, 'id'),
|
|
|
|
|
selector:<string>MapWrapper.get(map, 'selector'),
|
|
|
|
|
compileChildren:<boolean>MapWrapper.get(map, 'compileChildren'),
|
|
|
|
|
hostProperties:<Map<string, string>>_cloneIfPresent(MapWrapper.get(map, 'hostProperties')),
|
2015-06-09 12:33:40 +02:00
|
|
|
hostListeners:<Map<string, string>>_cloneIfPresent(MapWrapper.get(map, 'hostListeners')),
|
2015-05-18 11:57:20 -07:00
|
|
|
hostActions:<Map<string, string>>_cloneIfPresent(MapWrapper.get(map, 'hostActions')),
|
|
|
|
|
hostAttributes:<Map<string, string>>_cloneIfPresent(MapWrapper.get(map, 'hostAttributes')),
|
2015-05-26 15:54:10 +02:00
|
|
|
properties:<List<string>>_cloneIfPresent(MapWrapper.get(map, 'properties')),
|
2015-05-18 11:57:20 -07:00
|
|
|
readAttributes:<List<string>>_cloneIfPresent(MapWrapper.get(map, 'readAttributes')),
|
2015-05-28 17:28:53 -07:00
|
|
|
type:<number>MapWrapper.get(map, 'type'),
|
2015-06-04 13:45:08 -07:00
|
|
|
exportAs:<string>MapWrapper.get(map, 'exportAs'),
|
2015-05-28 17:28:53 -07:00
|
|
|
callOnDestroy:<boolean>MapWrapper.get(map, 'callOnDestroy'),
|
|
|
|
|
callOnCheck:<boolean>MapWrapper.get(map, 'callOnCheck'),
|
|
|
|
|
callOnChange:<boolean>MapWrapper.get(map, 'callOnChange'),
|
|
|
|
|
callOnInit:<boolean>MapWrapper.get(map, 'callOnInit'),
|
2015-06-12 09:50:30 +02:00
|
|
|
callOnAllChangesDone:<boolean>MapWrapper.get(map, 'callOnAllChangesDone'),
|
|
|
|
|
events:<List<string>>_cloneIfPresent(MapWrapper.get(map, 'events')),
|
|
|
|
|
changeDetection:<string>MapWrapper.get(map, '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
|
|
|
}
|