@@ -25,7 +25,8 @@ export class RouterSource {
25
25
private _history$ : any ,
26
26
private _namespace : Pathname [ ] ,
27
27
private _createHref : ( path : LocationDescriptorObject ) => Pathname ,
28
- private _routeMatcher : RouteMatcher
28
+ private _routeMatcher : RouteMatcher ,
29
+ private _name : string
29
30
) { }
30
31
31
32
history$ = adapt ( this . _history$ ) ;
@@ -45,19 +46,20 @@ export class RouterSource {
45
46
scopedHistory$ ,
46
47
scopedNamespace ,
47
48
createHref ,
48
- this . _routeMatcher
49
+ this . _routeMatcher ,
50
+ this . _name
49
51
) ;
50
52
}
51
53
52
- define (
54
+ private _define (
53
55
routes : RouteDefinitionsMap | RouteDefinitionsArray ,
54
56
routeMatcher ?: RouteMatcher
55
57
) : any {
56
58
const namespace = this . _namespace ;
57
59
const _createHref = this . _createHref ;
58
60
const createHref = util . makeCreateHref ( namespace , _createHref ) ;
59
61
60
- let match$ = this . _history$
62
+ return this . _history$
61
63
. map ( ( location : Location ) => {
62
64
const matcher = routeMatcher || this . _routeMatcher ;
63
65
const filteredPath = getFilteredPath (
@@ -69,12 +71,37 @@ export class RouterSource {
69
71
} )
70
72
. filter ( ( { path } : any ) => path !== undefined && path !== null )
71
73
. remember ( ) ;
74
+ }
75
+
76
+ define (
77
+ routes : RouteDefinitionsMap | RouteDefinitionsArray ,
78
+ routeMatcher ?: RouteMatcher
79
+ ) : any {
80
+ const _createHref = this . _createHref ;
81
+ const createHref = util . makeCreateHref ( this . _namespace , _createHref ) ;
72
82
73
- const out$ = adapt ( match$ ) ;
83
+ const out$ = adapt ( this . _define ( routes , routeMatcher ) ) ;
74
84
out$ . createHref = createHref ;
75
85
return out$ ;
76
86
}
77
87
88
+ routedComponent (
89
+ routes : RouteDefinitionsMap | RouteDefinitionsArray ,
90
+ routeMatcher ?: RouteMatcher
91
+ ) : ( sources : any ) => any {
92
+ const name = this . _name ;
93
+ return sources => {
94
+ const match$ = this . _define ( routes , routeMatcher ) ;
95
+ const page$ = match$ . map ( ( { path, value } : any ) => {
96
+ return value ( {
97
+ ...sources ,
98
+ [ name ] : sources [ name ] . path ( path )
99
+ } ) ;
100
+ } ) ;
101
+ return adapt ( page$ ) ;
102
+ } ;
103
+ }
104
+
78
105
createHref ( path : Pathname ) : Pathname {
79
106
return util . makeCreateHref ( this . _namespace , this . _createHref ) ( path ) ;
80
107
}
0 commit comments