Skip to content

Instantly share code, notes, and snippets.

@al6x
Last active October 13, 2023 05:20
Show Gist options
  • Save al6x/867702f8a1be91626ae71109ba6848d8 to your computer and use it in GitHub Desktop.
Save al6x/867702f8a1be91626ae71109ba6848d8 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 = CodeCmd(kind: eval, code: "alert('hi')")
dispatch(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment