-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeature.ts
33 lines (26 loc) · 1017 Bytes
/
feature.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {TemplateAction, RouterCurrentState, IRouterTemplate, TemplateReducer} from '../types';
/**
* A feature router does not interact with its sibling routers. It lives harmony with them
* making no judgements about their state.
*/
const show: TemplateAction = (_options, oldLocation, router, _ctx) => {
const location = {...oldLocation};
location.search[router.routeKey] = true;
return location;
};
const hide: TemplateAction = (_options, oldLocation, router, _ctx) => {
const location = {...oldLocation};
location.search[router.routeKey] = undefined;
return location;
};
const reducer: TemplateReducer = (location, router, _ctx) => {
const newState: Partial<RouterCurrentState> = {};
newState['visible'] = location.search[router.routeKey] === 'true';
return newState as RouterCurrentState;
};
const template: IRouterTemplate = {
actions: {show, hide},
reducer,
config: {canBePathRouter: false, shouldInverselyActivate: true}
};
export default template;