-
Notifications
You must be signed in to change notification settings - Fork 192
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
fae471e
commit 7d8a4d9
Showing
2 changed files
with
38 additions
and
0 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,25 @@ | ||
import { HyperFrame } from "./types"; | ||
|
||
const frames: Record<string, HyperFrame> = {}; | ||
|
||
export function addHyperFrame(label: string, frame: HyperFrame) { | ||
frames[label] = frame; | ||
} | ||
|
||
export function getHyperFrame(frame: string, text: string, button: number) { | ||
const currentFrame = frames[frame]; | ||
const nextFrameIdOrFunction = currentFrame[button as keyof HyperFrame]; | ||
|
||
let nextFrameId: string; | ||
if (typeof nextFrameIdOrFunction === 'function') { | ||
nextFrameId = nextFrameIdOrFunction(text); | ||
} else { | ||
nextFrameId = nextFrameIdOrFunction as string; | ||
} | ||
|
||
if (!frames[nextFrameId]) { | ||
throw new Error(`Frame not found: ${nextFrameId}`); | ||
} | ||
|
||
return frames[nextFrameId].frame; | ||
} |
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