-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Session String Generator] Make it possible to choose a library direc…
…tly with location hash
- Loading branch information
Showing
2 changed files
with
92 additions
and
29 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,15 @@ | ||
import { ReadonlySignal, signal } from "@preact/signals"; | ||
import { IS_BROWSER } from "$fresh/runtime.ts"; | ||
|
||
export function getHashSignal() { | ||
const signal_ = signal(IS_BROWSER ? location.hash : ""); | ||
|
||
IS_BROWSER && addEventListener("hashchange", () => { | ||
signal_.value = location.hash; | ||
}); | ||
IS_BROWSER && addEventListener("popstate", () => { | ||
signal_.value = location.hash; | ||
}); | ||
|
||
return signal_ as ReadonlySignal<string>; | ||
} |