2015-02-06 13:19:47 -08:00
|
|
|
import {ABSTRACT, CONST, normalizeBlank, isPresent} from 'angular2/src/facade/lang';
|
|
|
|
import {ListWrapper, List} from 'angular2/src/facade/collection';
|
2014-11-21 21:19:23 -08:00
|
|
|
|
2015-03-13 21:54:19 +00:00
|
|
|
/**
|
|
|
|
* Directives allow you to attach behavior to the DOM elements. Directive is an abstract concept, instead use concrete
|
|
|
|
* directives such as: [Component], [Decorator] or [Viewport].
|
|
|
|
*/
|
2014-11-21 21:19:23 -08:00
|
|
|
@ABSTRACT()
|
|
|
|
export class Directive {
|
|
|
|
selector:any; //string;
|
|
|
|
bind:any;
|
|
|
|
implementsTypes:any; //List;
|
2015-01-13 16:17:43 -08:00
|
|
|
lifecycle:any; //List
|
2015-03-06 15:44:59 +01:00
|
|
|
events:any; //List
|
2014-11-21 21:19:23 -08:00
|
|
|
@CONST()
|
|
|
|
constructor({
|
|
|
|
selector,
|
|
|
|
bind,
|
2015-03-06 15:44:59 +01:00
|
|
|
events,
|
2015-01-13 16:17:43 -08:00
|
|
|
implementsTypes,
|
|
|
|
lifecycle
|
2014-11-21 21:19:23 -08:00
|
|
|
}:{
|
|
|
|
selector:string,
|
|
|
|
bind:any,
|
2015-03-06 15:44:59 +01:00
|
|
|
events: any,
|
2015-01-13 16:17:43 -08:00
|
|
|
implementsTypes:List,
|
|
|
|
lifecycle:List
|
2014-11-21 21:19:23 -08:00
|
|
|
}={})
|
|
|
|
{
|
|
|
|
this.selector = selector;
|
|
|
|
this.implementsTypes = implementsTypes;
|
|
|
|
this.bind = bind;
|
2015-03-06 15:44:59 +01:00
|
|
|
this.events = events;
|
2015-01-13 16:17:43 -08:00
|
|
|
this.lifecycle = lifecycle;
|
2014-11-21 21:19:23 -08:00
|
|
|
}
|
2015-02-06 13:19:47 -08:00
|
|
|
|
|
|
|
hasLifecycleHook(hook:string):boolean {
|
|
|
|
return isPresent(this.lifecycle) ? ListWrapper.contains(this.lifecycle, hook) : false;
|
|
|
|
}
|
2014-11-21 21:19:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Component extends Directive {
|
|
|
|
//TODO: vsavkin: uncomment it once the issue with defining fields in a sublass works
|
2015-03-11 16:48:57 -07:00
|
|
|
services:any; //List;
|
2014-11-21 21:19:23 -08:00
|
|
|
|
2015-01-13 16:17:43 -08:00
|
|
|
@CONST()
|
2014-11-21 21:19:23 -08:00
|
|
|
constructor({
|
|
|
|
selector,
|
|
|
|
bind,
|
2015-03-06 15:44:59 +01:00
|
|
|
events,
|
2015-03-11 16:48:57 -07:00
|
|
|
services,
|
2014-12-23 10:45:20 -08:00
|
|
|
implementsTypes,
|
2015-01-13 16:17:43 -08:00
|
|
|
lifecycle
|
2014-11-21 21:19:23 -08:00
|
|
|
}:{
|
2015-01-13 16:17:43 -08:00
|
|
|
selector:String,
|
2014-11-21 21:19:23 -08:00
|
|
|
bind:Object,
|
2015-03-06 15:44:59 +01:00
|
|
|
events:Object,
|
2015-03-11 16:48:57 -07:00
|
|
|
services:List,
|
2014-12-23 10:45:20 -08:00
|
|
|
implementsTypes:List,
|
2015-01-13 16:17:43 -08:00
|
|
|
lifecycle:List
|
|
|
|
}={})
|
2014-11-21 21:19:23 -08:00
|
|
|
{
|
|
|
|
super({
|
|
|
|
selector: selector,
|
|
|
|
bind: bind,
|
2015-03-06 15:44:59 +01:00
|
|
|
events: events,
|
2015-01-13 16:17:43 -08:00
|
|
|
implementsTypes: implementsTypes,
|
|
|
|
lifecycle: lifecycle
|
|
|
|
});
|
2014-11-21 21:19:23 -08:00
|
|
|
|
2015-03-11 16:48:57 -07:00
|
|
|
this.services = services;
|
2014-11-21 21:19:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Decorator extends Directive {
|
2015-01-07 17:32:46 +01:00
|
|
|
compileChildren: boolean;
|
2014-11-21 21:19:23 -08:00
|
|
|
@CONST()
|
|
|
|
constructor({
|
|
|
|
selector,
|
|
|
|
bind,
|
2015-03-06 15:44:59 +01:00
|
|
|
events,
|
2015-01-07 18:20:29 +01:00
|
|
|
implementsTypes,
|
2015-01-13 16:17:43 -08:00
|
|
|
lifecycle,
|
|
|
|
compileChildren = true,
|
2014-11-21 21:19:23 -08:00
|
|
|
}:{
|
|
|
|
selector:string,
|
|
|
|
bind:any,
|
2015-03-06 15:44:59 +01:00
|
|
|
events:any,
|
2015-01-07 18:20:29 +01:00
|
|
|
implementsTypes:List,
|
2015-01-13 16:17:43 -08:00
|
|
|
lifecycle:List,
|
2015-01-07 18:20:29 +01:00
|
|
|
compileChildren:boolean
|
2014-11-21 21:19:23 -08:00
|
|
|
}={})
|
|
|
|
{
|
2015-01-07 18:20:29 +01:00
|
|
|
this.compileChildren = compileChildren;
|
2014-11-21 21:19:23 -08:00
|
|
|
super({
|
|
|
|
selector: selector,
|
|
|
|
bind: bind,
|
2015-03-06 15:44:59 +01:00
|
|
|
events: events,
|
2015-01-13 16:17:43 -08:00
|
|
|
implementsTypes: implementsTypes,
|
|
|
|
lifecycle: lifecycle
|
2014-11-21 21:19:23 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-12 11:54:22 +01:00
|
|
|
export class Viewport extends Directive {
|
2014-11-21 21:19:23 -08:00
|
|
|
@CONST()
|
|
|
|
constructor({
|
|
|
|
selector,
|
|
|
|
bind,
|
2015-03-06 15:44:59 +01:00
|
|
|
events,
|
2015-01-13 16:17:43 -08:00
|
|
|
implementsTypes,
|
|
|
|
lifecycle
|
2014-11-21 21:19:23 -08:00
|
|
|
}:{
|
|
|
|
selector:string,
|
|
|
|
bind:any,
|
2015-01-13 16:17:43 -08:00
|
|
|
implementsTypes:List,
|
|
|
|
lifecycle:List
|
2014-11-21 21:19:23 -08:00
|
|
|
}={})
|
|
|
|
{
|
|
|
|
super({
|
|
|
|
selector: selector,
|
|
|
|
bind: bind,
|
2015-03-06 15:44:59 +01:00
|
|
|
events: events,
|
2015-01-13 16:17:43 -08:00
|
|
|
implementsTypes: implementsTypes,
|
|
|
|
lifecycle: lifecycle
|
2014-11-21 21:19:23 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-01-13 16:17:43 -08:00
|
|
|
|
2015-02-06 13:19:47 -08:00
|
|
|
export const onDestroy = "onDestroy";
|
|
|
|
export const onChange = "onChange";
|