Seriously...
    
    
    type
      CommandKind = enum eval, replace
      CodeCmd = object # not required, but makes my point clearer
         code: string
      ReplaceCmd = object
          element_id: string
          content:    string
      
      Command = object
        case kind: CommandKind
        of eval:
          c:       CodeCmd
        of replace:
          r: 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.c)
      of replace:
        exec_replace(command.r)
    
    let c = Command(kind: eval, c: CodeCmd(code: "alert('hi')"))
    dispatch(c)
    
    
    
    Run

Reply via email to