-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3805cff
commit 5feb082
Showing
4 changed files
with
46 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import RouteInfo from "@ember/routing/-private/route-info"; | ||
|
||
export function dynamicSegmentsFromRouteInfo(routeInfo?: RouteInfo | null): string[] { | ||
const parts: string[] = []; | ||
|
||
if (!routeInfo) { | ||
return parts; | ||
} | ||
|
||
if (routeInfo && routeInfo.paramNames) { | ||
const parentValues = dynamicSegmentsFromRouteInfo(routeInfo.parent); | ||
// TODO: fix type | ||
const values: any = routeInfo.paramNames.map(k => routeInfo.params[k]); | ||
|
||
parts.push( | ||
...parentValues, | ||
...values, | ||
); | ||
} | ||
|
||
return parts; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as qs from 'qs'; | ||
|
||
export function urlFromCache(routePath: string, dynamicSegmentValues: string[], cache: QueryParamsByPath) { | ||
const { protocol, host, pathname, search, hash } = window.location; | ||
const queryParams = cache[routePath]; | ||
const existing = qs.parse(search.split('?')[1]); | ||
const query = qs.stringify({ ...existing, ...queryParams }); | ||
const newUrl = `${protocol}//${host}${pathname}${hash}?${query}`; | ||
|
||
|
||
return newUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface QueryParams { | ||
[key: string]: number | string | undefined | QueryParams; | ||
} | ||
|
||
interface QueryParamsByPath { | ||
[key: string]: QueryParams; | ||
} |