mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
hook, store 리네이밍
This commit is contained in:
33
src/lib/hooks/gotoStateful.ts
Normal file
33
src/lib/hooks/gotoStateful.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { goto } from "$app/navigation";
|
||||
|
||||
type Path = "/key/export";
|
||||
|
||||
interface KeyExportState {
|
||||
pubKeyBase64: string;
|
||||
privKeyBase64: string;
|
||||
}
|
||||
|
||||
const useAutoNull = <T>(value: T | null) => {
|
||||
return {
|
||||
get: () => {
|
||||
const result = value;
|
||||
value = null;
|
||||
return result;
|
||||
},
|
||||
set: (newValue: T) => {
|
||||
value = newValue;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const keyExportState = useAutoNull<KeyExportState>(null);
|
||||
|
||||
export function gotoStateful(path: "/key/export", state: KeyExportState): Promise<void>;
|
||||
|
||||
export function gotoStateful(path: Path, state: unknown) {
|
||||
switch (path) {
|
||||
case "/key/export":
|
||||
keyExportState.set(state as KeyExportState);
|
||||
return goto(path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user