1
1
/** @module view */ /** for typedoc */
2
2
import { equals , applyPairs , removeFrom , TypedMap } from "../common/common" ;
3
3
import { curry , prop } from "../common/hof" ;
4
- import { isString } from "../common/predicates" ;
4
+ import { isString , isArray } from "../common/predicates" ;
5
5
import { trace } from "../common/module" ;
6
6
import { Node } from "../path/node" ;
7
7
@@ -11,7 +11,7 @@ import {_ViewDeclaration} from "../state/interface";
11
11
const match = ( obj1 , ...keys ) =>
12
12
( obj2 ) => keys . reduce ( ( memo , key ) => memo && obj1 [ key ] === obj2 [ key ] , true ) ;
13
13
14
- export type ViewConfigFactory = ( node : Node , decl : _ViewDeclaration ) => ViewConfig ;
14
+ export type ViewConfigFactory = ( node : Node , decl : _ViewDeclaration ) => ViewConfig | ViewConfig [ ] ;
15
15
16
16
/**
17
17
* The View service
@@ -32,10 +32,11 @@ export class ViewService {
32
32
this . _viewConfigFactories [ viewType ] = factory ;
33
33
}
34
34
35
- createViewConfig ( node : Node , decl : _ViewDeclaration ) : ViewConfig {
35
+ createViewConfig ( node : Node , decl : _ViewDeclaration ) : ViewConfig [ ] {
36
36
let cfgFactory = this . _viewConfigFactories [ decl . $type ] ;
37
37
if ( ! cfgFactory ) throw new Error ( "ViewService: No view config factory registered for type " + decl . $type ) ;
38
- return cfgFactory ( node , decl ) ;
38
+ let cfgs = cfgFactory ( node , decl ) ;
39
+ return isArray ( cfgs ) ? cfgs : [ cfgs ] ;
39
40
}
40
41
41
42
/**
@@ -66,6 +67,8 @@ export class ViewService {
66
67
* A ViewConfig has a target ui-view name and a context anchor. The ui-view name can be a simple name, or
67
68
* can be a segmented ui-view path, describing a portion of a ui-view fqn.
68
69
*
70
+ * In order for a ui-view to match ViewConfig, ui-view's $type must match the ViewConfig's $type
71
+ *
69
72
* If the ViewConfig's target ui-view name is a simple name (no dots), then a ui-view matches if:
70
73
* - the ui-view's name matches the ViewConfig's target name
71
74
* - the ui-view's context matches the ViewConfig's anchor
@@ -111,6 +114,9 @@ export class ViewService {
111
114
* the tail of the ui-view's fqn "default.bar"
112
115
*/
113
116
const matches = ( uiView : ActiveUIView ) => ( viewConfig : ViewConfig ) => {
117
+ // Don't supply an ng1 ui-view with an ng2 ViewConfig, etc
118
+ if ( uiView . $type !== viewConfig . viewDecl . $type ) return false ;
119
+
114
120
// Split names apart from both viewConfig and uiView into segments
115
121
let vc = viewConfig . viewDecl ;
116
122
let vcSegments = vc . $uiViewName . split ( "." ) ;
0 commit comments