- Notifications
You must be signed in to change notification settings - Fork 539
/
Copy pathsimple.ts
39 lines (35 loc) · 1.13 KB
/
simple.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
34
35
36
37
38
39
importtype{UiState,IndexUiState,StateMapping}from'../../types';
functiongetIndexStateWithoutConfigure<TIndexUiStateextendsIndexUiState>(
uiState: TIndexUiState
): Omit<TIndexUiState,'configure'>{
const{ configure, ...trackedUiState}=uiState;
returntrackedUiState;
}
// technically a URL could contain any key, since users provide it,
// which is why the input to this function is UiState, not something
// which excludes "configure" as this function does.
exportdefaultfunctionsimpleStateMapping<
TUiStateextendsUiState=UiState
>(): StateMapping<TUiState,TUiState>{
return{
$$type: 'ais.simple',
stateToRoute(uiState){
returnObject.keys(uiState).reduce(
(state,indexId)=>({
...state,
[indexId]: getIndexStateWithoutConfigure(uiState[indexId]),
}),
{}asTUiState
);
},
routeToState(routeState={}asTUiState){
returnObject.keys(routeState).reduce(
(state,indexId)=>({
...state,
[indexId]: getIndexStateWithoutConfigure(routeState[indexId]),
}),
{}asTUiState
);
},
};
}