Last active
October 13, 2023 05:20
-
-
Save al6x/867702f8a1be91626ae71109ba6848d8 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 = 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