Skip to content

Instantly share code, notes, and snippets.

@al6x
Created October 13, 2023 05:11
Show Gist options
  • Save al6x/20e9339ef81bf6fb4837159e97d893e5 to your computer and use it in GitHub Desktop.
Save al6x/20e9339ef81bf6fb4837159e97d893e5 to your computer and use it in GitHub Desktop.
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