-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-history-sync): sort routes by variable count (#448)
- Loading branch information
1 parent
ffa4c06
commit 36613e3
Showing
18 changed files
with
178 additions
and
98 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,7 @@ | ||
--- | ||
"@stackflow/plugin-history-sync": minor | ||
"@stackflow/plugin-preload": minor | ||
"@stackflow/link": minor | ||
--- | ||
|
||
Sort routes by variable count and refactor useRoutes(), normalizeRouteInput() function |
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,4 @@ | ||
export type ActivityRoute = { | ||
activityName: string; | ||
path: string; | ||
}; |
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,3 @@ | ||
export type ActivityRouteMapInput = { | ||
[activityName in string]?: string | string[]; | ||
}; |
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export { useHistoryTick } from "./HistoryQueueContext"; | ||
export * from "./historySyncPlugin"; | ||
export { makeTemplate, UrlPatternOptions } from "./makeTemplate"; | ||
export { normalizeRoute } from "./normalizeRoute"; | ||
export { useRoutes } from "./RoutesContext"; |
File renamed without changes.
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
23 changes: 23 additions & 0 deletions
23
extensions/plugin-history-sync/src/normalizeActivityRouteMap.spec.ts
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,23 @@ | ||
import { normalizeActivityRouteMap } from "./normalizeActivityRouteMap"; | ||
|
||
test("normalizeActivityRouteMap", () => { | ||
expect( | ||
normalizeActivityRouteMap({ | ||
Hello: ["/hello", "/hello-2"], | ||
World: "/world", | ||
}), | ||
).toStrictEqual([ | ||
{ | ||
activityName: "Hello", | ||
path: "/hello", | ||
}, | ||
{ | ||
activityName: "Hello", | ||
path: "/hello-2", | ||
}, | ||
{ | ||
activityName: "World", | ||
path: "/world", | ||
}, | ||
]); | ||
}); |
22 changes: 22 additions & 0 deletions
22
extensions/plugin-history-sync/src/normalizeActivityRouteMap.ts
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 type { ActivityRoute } from "./ActivityRoute"; | ||
import type { ActivityRouteMapInput } from "./ActivityRouteMapInput"; | ||
import { normalizeRouteInput } from "./normalizeRouteInput"; | ||
|
||
export function normalizeActivityRouteMap<T extends ActivityRouteMapInput>( | ||
activityRouteMap: T, | ||
): ActivityRoute[] { | ||
const routes = Object.keys(activityRouteMap).flatMap((activityName) => { | ||
const routeInput = activityRouteMap[activityName]; | ||
|
||
if (!routeInput) { | ||
return []; | ||
} | ||
|
||
return normalizeRouteInput(routeInput).map((path) => ({ | ||
activityName, | ||
path, | ||
})); | ||
}); | ||
|
||
return routes; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
extensions/plugin-history-sync/src/normalizeRouteInput.spec.ts
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,9 @@ | ||
import { normalizeRouteInput } from "./normalizeRouteInput"; | ||
|
||
test("normalizeRouteInput - string이 들어오면 [string]으로 만듭니다", () => { | ||
expect(normalizeRouteInput("/home")).toEqual(["/home"]); | ||
}); | ||
|
||
test("normalizeRouteInput - string[]이 들어오면 string[]인채로 반환합니다", () => { | ||
expect(normalizeRouteInput(["/home"])).toEqual(["/home"]); | ||
}); |
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,3 @@ | ||
export function normalizeRouteInput(route: string | string[]) { | ||
return typeof route === "string" ? [route] : route; | ||
} |
Oops, something went wrong.