1
1
/** @module ng2_directives */ /** */
2
2
import {
3
3
Component , ComponentResolver , ComponentFactory ,
4
- ViewContainerRef , ReflectiveInjector
4
+ ViewContainerRef , ReflectiveInjector , InputMetadata , ComponentMetadata
5
5
} from '@angular/core' ;
6
6
import { provide } from "@angular/core" ;
7
7
import { Input } from "@angular/core" ;
8
8
import { ComponentRef } from "@angular/core" ;
9
9
import { Type } from "@angular/core" ;
10
10
11
- import { UIRouter } from "../router" ;
12
- import { trace } from "../common/trace" ;
11
+ import { UIRouter } from "../../ router" ;
12
+ import { trace } from "../../ common/trace" ;
13
13
import { Inject } from "@angular/core" ;
14
- import { ViewContext , ViewConfig } from "../view/interface" ;
15
- import { Ng2ViewDeclaration } from "./interface" ;
16
- import { ng2ComponentInputs } from "./componentUtil" ;
17
- import { Ng2ViewConfig } from "./viewsBuilder" ;
14
+ import { ViewContext , ViewConfig } from "../../view/interface" ;
15
+ import { Ng2ViewDeclaration } from "../interface" ;
16
+ import { Ng2ViewConfig } from "../statebuilders/views" ;
18
17
19
18
/** @hidden */
20
19
let id = 0 ;
@@ -25,6 +24,34 @@ export interface ParentUiViewInject {
25
24
fqn : string ;
26
25
}
27
26
27
+
28
+ /** @hidden */
29
+ const ng2ComponentInputs = ( ng2CompClass ) => {
30
+ /** Get "@Input('foo') _foo" inputs */
31
+ let props = Reflect [ 'getMetadata' ] ( 'propMetadata' , ng2CompClass ) ;
32
+ let _props = Object . keys ( props || { } )
33
+ // -> { string, anno[] } tuples
34
+ . map ( key => ( { key, annoArr : props [ key ] } ) )
35
+ // -> to { string, anno } tuples
36
+ . reduce ( ( acc , tuple ) => acc . concat ( tuple . annoArr . map ( anno => ( { key : tuple . key , anno } ) ) ) , [ ] )
37
+ // Only Inputs
38
+ . filter ( tuple => tuple . anno instanceof InputMetadata )
39
+ // If they have a bindingPropertyName, i.e. "@Input('foo') _foo", then foo, else _foo
40
+ . map ( tuple => ( { resolve : tuple . anno . bindingPropertyName || tuple . key , prop : tuple . key } ) ) ;
41
+
42
+ /** Get "inputs: ['foo']" inputs */
43
+ let inputs = Reflect [ 'getMetadata' ] ( 'annotations' , ng2CompClass )
44
+ // Find the ComponentMetadata class annotation
45
+ . filter ( x => x instanceof ComponentMetadata && ! ! x . inputs )
46
+ // Get the .inputs string array
47
+ . map ( x => x . inputs )
48
+ // Flatten
49
+ . reduce ( ( acc , arr ) => acc . concat ( arr ) , [ ] )
50
+ . map ( input => ( { resolve : input , prop : input } ) ) ;
51
+
52
+ return _props . concat ( inputs ) ;
53
+ } ;
54
+
28
55
/**
29
56
* A UI-Router viewport directive, which is filled in by a view (component) on a state.
30
57
*
0 commit comments