Created
October 13, 2023 05:11
-
-
Save al6x/20e9339ef81bf6fb4837159e97d893e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type | |
CommandKind = enum eval, replace | |
CodeCmd = object # not required, but makes my point clearer | |
kind: eval | |
code: string | |
ReplaceCmd = object | |
kind: replace | |
element_id: string | |
content: string | |
Command = CodeCmd | ReplaceCmd | |
proc exec_eval(command: CodeCmd) = | |
discard | |
proc exec_replace(command: ReplaceCmd) = | |
discard | |
proc dispatch(command: Command) = | |
case command.kind | |
of eval: | |
exec_eval(command) | |
of replace: | |
exec_replace(command) | |
let c = Command(kind: eval, c: CodeCmd(code: "alert('hi')")) | |
dispatch(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment