-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
40 additions
and
24 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
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,18 @@ | ||
export function localStorageProvider(): Map<string, any> { | ||
// 初期化時に、 `localStorage` から Map にデータを復元します。 | ||
const map = new Map<string, any>( | ||
JSON.parse(localStorage.getItem("app-cache") ?? "[]") as | ||
| Iterable<readonly [string, any]> | ||
| null | ||
| undefined, | ||
); | ||
|
||
// アプリが終了する前に、すべてのデータを `localStorage` に保存します。 | ||
window.addEventListener("beforeunload", () => { | ||
const appCache = JSON.stringify(Array.from(map.entries())); | ||
localStorage.setItem("app-cache", appCache); | ||
}); | ||
|
||
// パフォーマンスのために、書き込みと読み取りには引き続き Map を使用します。 | ||
return map; | ||
} |
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,7 +1,13 @@ | ||
import { Routes } from "@generouted/react-router"; | ||
import { createRoot } from "react-dom/client"; | ||
import { SWRConfig } from "swr"; | ||
import { localStorageProvider } from "@/lib/localstorage"; | ||
|
||
const root = document.getElementById("root"); | ||
if (root == null) throw new Error("Root element not found"); | ||
|
||
createRoot(root).render(<Routes />); | ||
createRoot(root).render( | ||
<SWRConfig value={{ provider: localStorageProvider }}> | ||
<Routes /> | ||
</SWRConfig>, | ||
); |
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
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