diff --git a/john_titor/shadow-cljs.edn b/john_titor/shadow-cljs.edn index 155c74c..5bedb78 100644 --- a/john_titor/shadow-cljs.edn +++ b/john_titor/shadow-cljs.edn @@ -1,6 +1,6 @@ {:source-paths ["src"] - :dependencies [[cljs-http "0.1.45"] - [cider/cider-nrepl "0.18.0-SNAPSHOT"]] + :dependencies [[cljs-http "0.1.45"]] + :nrepl {:port 8282} :builds diff --git a/john_titor/src/john_titor/commands.cljs b/john_titor/src/john_titor/commands.cljs new file mode 100644 index 0000000..e0f7366 --- /dev/null +++ b/john_titor/src/john_titor/commands.cljs @@ -0,0 +1,8 @@ +(ns john-titor.commands + (:require + [john-titor.commands.protocols :as impl] + [john-titor.commands.echo :as echo])) + +(defn router + [server] + (impl/init (echo/->EchoCommand) server)) diff --git a/john_titor/src/john_titor/commands/echo.cljs b/john_titor/src/john_titor/commands/echo.cljs new file mode 100644 index 0000000..b0f7b6d --- /dev/null +++ b/john_titor/src/john_titor/commands/echo.cljs @@ -0,0 +1,11 @@ +(ns john-titor.commands.echo + (:require + [john-titor.commands.protocols :as proto :refer [defcommand]])) + +(defn- echo [msg] + (str msg "/" msg)) + +(deftype EchoCommand [] + proto/CommandRouter + (init [_ server] + (defcommand server "echo" #(echo %)))) diff --git a/john_titor/src/john_titor/commands/protocols.cljs b/john_titor/src/john_titor/commands/protocols.cljs new file mode 100644 index 0000000..c98c5c0 --- /dev/null +++ b/john_titor/src/john_titor/commands/protocols.cljs @@ -0,0 +1,8 @@ +(ns john-titor.commands.protocols) + +(defn defcommand [server command-name f] + (.defineMethod server command-name f)) + +(defprotocol CommandRouter + (init [_ server] + "Define all the commands using the given `server`.")) diff --git a/john_titor/src/john_titor/core.cljs b/john_titor/src/john_titor/core.cljs index fcf635d..114ae81 100644 --- a/john_titor/src/john_titor/core.cljs +++ b/john_titor/src/john_titor/core.cljs @@ -1,12 +1,16 @@ - (ns john-titor.core (:require-macros [cljs.core.async.macros :refer [go]]) (:require ["xhr2" :as xhr2] - [cljs-http.client :as http] - [cljs.core.async :refer [