1
1
/** @module ng1 */ /** */
2
2
import { ng as angular } from "../../angular" ;
3
3
import {
4
- State , Obj , pick , forEach , anyTrueR , unnestR , tail , extend , kebobString ,
5
- isArray , isInjectable , isDefined , isString , isObject , services , trace ,
4
+ State , pick , forEach , anyTrueR , tail , extend ,
5
+ isArray , isInjectable , isDefined , isString , services , trace ,
6
6
ViewConfig , ViewService , ViewConfigFactory , PathNode , ResolveContext , Resolvable , RawParams , IInjectable
7
7
} from "ui-router-core" ;
8
8
import { Ng1ViewDeclaration } from "../interface" ;
@@ -24,7 +24,7 @@ export const ng1ViewConfigFactory: ViewConfigFactory = (path, view) =>
24
24
export function ng1ViewsBuilder ( state : State ) {
25
25
let tplKeys = [ 'templateProvider' , 'templateUrl' , 'template' , 'notify' , 'async' ] ,
26
26
ctrlKeys = [ 'controller' , 'controllerProvider' , 'controllerAs' , 'resolveAs' ] ,
27
- compKeys = [ 'component' , 'bindings' ] ,
27
+ compKeys = [ 'component' , 'bindings' , 'componentProvider' ] ,
28
28
nonCompKeys = tplKeys . concat ( ctrlKeys ) ,
29
29
allKeys = compKeys . concat ( nonCompKeys ) ;
30
30
@@ -43,24 +43,6 @@ export function ng1ViewsBuilder(state: State) {
43
43
if ( nonCompKeys . map ( key => isDefined ( config [ key ] ) ) . reduce ( anyTrueR , false ) ) {
44
44
throw new Error ( `Cannot combine: ${ compKeys . join ( "|" ) } with: ${ nonCompKeys . join ( "|" ) } in stateview: 'name@${ state . name } '` ) ;
45
45
}
46
-
47
- // Dynamically build a template like "<component-name input1='::$resolve.foo'></component-name>"
48
- config . templateProvider = [ '$injector' , function ( $injector : IInjectorService ) {
49
- const resolveFor = ( key : string ) =>
50
- config . bindings && config . bindings [ key ] || key ;
51
- const prefix = angular . version . minor >= 3 ? "::" : "" ;
52
- const attributeTpl = ( input : BindingTuple ) => {
53
- var attrName = kebobString ( input . name ) ;
54
- var resolveName = resolveFor ( input . name ) ;
55
- if ( input . type === '@' )
56
- return `${ attrName } ='{{${ prefix } $resolve.${ resolveName } }}'` ;
57
- return `${ attrName } ='${ prefix } $resolve.${ resolveName } '` ;
58
- } ;
59
-
60
- let attrs = getComponentInputs ( $injector , config . component ) . map ( attributeTpl ) . join ( " " ) ;
61
- let kebobName = kebobString ( config . component ) ;
62
- return `<${ kebobName } ${ attrs } ></${ kebobName } >` ;
63
- } ] ;
64
46
}
65
47
66
48
config . resolveAs = config . resolveAs || '$resolve' ;
@@ -77,35 +59,6 @@ export function ng1ViewsBuilder(state: State) {
77
59
return views ;
78
60
}
79
61
80
- interface BindingTuple {
81
- name : string ;
82
- type : string ;
83
- }
84
-
85
- // for ng 1.2 style, process the scope: { input: "=foo" }
86
- // for ng 1.3 through ng 1.5, process the component's bindToController: { input: "=foo" } object
87
- const scopeBindings = ( bindingsObj : Obj ) => Object . keys ( bindingsObj || { } )
88
- // [ 'input', [ '=foo', '=', 'foo' ] ]
89
- . map ( key => [ key , / ^ ( [ = < @ ] ) [ ? ] ? ( .* ) / . exec ( bindingsObj [ key ] ) ] )
90
- // skip malformed values
91
- . filter ( tuple => isDefined ( tuple ) && isArray ( tuple [ 1 ] ) )
92
- // { name: ('foo' || 'input'), type: '=' }
93
- . map ( tuple => ( { name : tuple [ 1 ] [ 2 ] || tuple [ 0 ] , type : tuple [ 1 ] [ 1 ] } as BindingTuple ) ) ;
94
-
95
- // Given a directive definition, find its object input attributes
96
- // Use different properties, depending on the type of directive (component, bindToController, normal)
97
- const getBindings = ( def : any ) => {
98
- if ( isObject ( def . bindToController ) ) return scopeBindings ( def . bindToController ) ;
99
- return scopeBindings ( def . scope ) ;
100
- } ;
101
-
102
- // Gets all the directive(s)' inputs ('@', '=', and '<')
103
- function getComponentInputs ( $injector : IInjectorService , name : string ) {
104
- let cmpDefs = < any [ ] > $injector . get ( name + "Directive" ) ; // could be multiple
105
- if ( ! cmpDefs || ! cmpDefs . length ) throw new Error ( `Unable to find component named '${ name } '` ) ;
106
- return cmpDefs . map ( getBindings ) . reduce ( unnestR , [ ] ) ;
107
- }
108
-
109
62
let id = 0 ;
110
63
export class Ng1ViewConfig implements ViewConfig {
111
64
$id = id ++ ;
@@ -144,7 +97,7 @@ export class Ng1ViewConfig implements ViewConfig {
144
97
* @return {boolean } Returns `true` if the configuration contains a valid template, otherwise `false`.
145
98
*/
146
99
hasTemplate ( ) {
147
- return ! ! ( this . viewDecl . template || this . viewDecl . templateUrl || this . viewDecl . templateProvider ) ;
100
+ return ! ! ( this . viewDecl . template || this . viewDecl . templateUrl || this . viewDecl . templateProvider || this . viewDecl . component || this . viewDecl . componentProvider ) ;
148
101
}
149
102
150
103
getTemplate ( params : RawParams , $factory : TemplateFactory , context : ResolveContext ) {
0 commit comments