11/** @module view */ /** for typedoc */
22import { equals , applyPairs , removeFrom , TypedMap } from "../common/common" ;
33import { curry , prop } from "../common/hof" ;
4- import { isString } from "../common/predicates" ;
4+ import { isString , isArray } from "../common/predicates" ;
55import { trace } from "../common/module" ;
66import { Node } from "../path/node" ;
77
@@ -11,7 +11,7 @@ import {_ViewDeclaration} from "../state/interface";
1111const match = ( obj1 , ...keys ) =>
1212 ( obj2 ) => keys . reduce ( ( memo , key ) => memo && obj1 [ key ] === obj2 [ key ] , true ) ;
1313
14- export type ViewConfigFactory = ( node : Node , decl : _ViewDeclaration ) => ViewConfig ;
14+ export type ViewConfigFactory = ( node : Node , decl : _ViewDeclaration ) => ViewConfig | ViewConfig [ ] ;
1515
1616/**
1717 * The View service
@@ -32,10 +32,11 @@ export class ViewService {
3232 this . _viewConfigFactories [ viewType ] = factory ;
3333 }
3434
35- createViewConfig ( node : Node , decl : _ViewDeclaration ) : ViewConfig {
35+ createViewConfig ( node : Node , decl : _ViewDeclaration ) : ViewConfig [ ] {
3636 let cfgFactory = this . _viewConfigFactories [ decl . $type ] ;
3737 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 ] ;
3940 }
4041
4142 /**
@@ -66,6 +67,8 @@ export class ViewService {
6667 * A ViewConfig has a target ui-view name and a context anchor. The ui-view name can be a simple name, or
6768 * can be a segmented ui-view path, describing a portion of a ui-view fqn.
6869 *
70+ * In order for a ui-view to match ViewConfig, ui-view's $type must match the ViewConfig's $type
71+ *
6972 * If the ViewConfig's target ui-view name is a simple name (no dots), then a ui-view matches if:
7073 * - the ui-view's name matches the ViewConfig's target name
7174 * - the ui-view's context matches the ViewConfig's anchor
@@ -111,6 +114,9 @@ export class ViewService {
111114 * the tail of the ui-view's fqn "default.bar"
112115 */
113116 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+
114120 // Split names apart from both viewConfig and uiView into segments
115121 let vc = viewConfig . viewDecl ;
116122 let vcSegments = vc . $uiViewName . split ( "." ) ;
0 commit comments