1- /**
2- * Created by voland on 4/2/16.
3- */
1+ import { appName } from "./app.config" ;
42
53const module = function ( moduleOrName ) {
64 return typeof moduleOrName === "string"
@@ -13,36 +11,58 @@ export function Component(options: {
1311 controllerAs ?: string ,
1412 template ?: string ,
1513 templateUrl ?: string ,
16- bindings ? : any
17- } , moduleOrName : string | ng . IModule = 'app.components' ) {
18- return ( controller : Function ) => {
19- let selector = options . selector ;
14+ bindings ?: any ,
15+ directives ?: any [ ]
16+ pipes ?: any [ ]
17+ providers ?: any [ ]
18+ } , moduleOrName : string | ng . IModule = `${ appName } .components` ) {
19+ return ( controller : any ) => {
20+ const selector = options . selector ;
2021 delete options . selector ;
22+ delete options . directives ;
23+ delete options . pipes ;
24+ delete options . providers ;
2125 module ( moduleOrName ) . component ( selector , angular . extend ( options , { controller : controller } ) ) ;
2226 }
2327}
2428
25- export function Service ( moduleOrName : string | ng . IModule = 'app .services' ) {
29+ export function Service ( moduleOrName : string | ng . IModule = ` ${ appName } .services` ) {
2630 return ( service : any ) => {
27- let name = service . name ;
31+ const name = service . name ;
32+ const isProvider = service . hasOwnProperty ( '$get' ) ;
2833 if ( ! name ) {
2934 console . error ( 'Service decorator can be used with named class only' ) ;
3035 }
31- module ( moduleOrName ) . service ( name , service ) ;
36+ module ( moduleOrName ) [ isProvider ? 'provider' : ' service' ] ( name , service ) ;
3237 }
3338}
3439
40+ interface PipeTransformStatic {
41+ new ( ...args : any [ ] ) : PipeTransform ;
42+ }
43+
3544export interface PipeTransform {
3645 transform ( value : any , ...args : any [ ] ) : any ;
3746}
3847
39- interface PipeTransformStatic {
40- new ( ...args : any [ ] ) : PipeTransform ;
48+ export function Pipe ( options : { name : string } , moduleOrName : string | ng . IModule = `${ appName } .pipes` ) {
49+ return ( Pipe : PipeTransformStatic ) => {
50+ const filter = ( ) => {
51+ const $injector = angular . injector ( [ 'ng' ] ) ;
52+ const instance :any = $injector . instantiate ( Pipe ) ;
53+ return instance . transform . bind ( instance ) ;
54+ } ;
55+ module ( moduleOrName ) . filter ( options . name , filter ) ;
56+ }
4157}
4258
43- export function Pipe ( options : { name : string } , moduleOrName : string | ng . IModule = 'app.pipes' ) {
44- return ( Pipe : PipeTransformStatic ) => {
45- let instance = new Pipe ( ) ;
46- module ( moduleOrName ) . filter ( options . name , ( ) => instance . transform ) ;
59+ export function Bootstrap ( appName : string , appClass : any ) {
60+ return ( anything : any ) => {
61+ if ( ! appClass ) {
62+ console . error ( `Please provide main component class as a second argument to @Bootstrap decorator` ) ;
63+ }
64+ angular . element ( document ) . ready ( ( ) => {
65+ angular . bootstrap ( document , [ appName ] ) ;
66+ } ) ;
4767 }
4868}
0 commit comments