From 1f47b1bc42cb35a0c0bf7366eaa7f63afe529971 Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Fri, 5 Aug 2016 12:40:07 +1200 Subject: [PATCH] [#257] Ref example: add disconnect and reconnect buttons (@danielcompton) --- example-project/src/example/client.cljs | 12 ++++++++++++ example-project/src/example/server.clj | 3 +++ 2 files changed, 15 insertions(+) diff --git a/example-project/src/example/client.cljs b/example-project/src/example/client.cljs index 618da8f..7cfa629 100644 --- a/example-project/src/example/client.cljs +++ b/example-project/src/example/client.cljs @@ -128,6 +128,18 @@ (->output! "Async broadcast loop now enabled") (->output! "Async broadcast loop now disabled"))))))))) +(when-let [target-el (.getElementById js/document "btn5")] + (.addEventListener target-el "click" + (fn [ev] + (->output! "Disconnecting") + (sente/chsk-disconnect! chsk)))) + +(when-let [target-el (.getElementById js/document "btn6")] + (.addEventListener target-el "click" + (fn [ev] + (->output! "Reconnecting") + (sente/chsk-reconnect! chsk)))) + (when-let [target-el (.getElementById js/document "btn-login")] (.addEventListener target-el "click" (fn [ev] diff --git a/example-project/src/example/server.clj b/example-project/src/example/server.clj index 27a5e47..b8f945b 100644 --- a/example-project/src/example/server.clj +++ b/example-project/src/example/server.clj @@ -74,6 +74,9 @@ [:p [:button#btn3 {:type "button"} "Test rapid server>user async pushes"] [:button#btn4 {:type "button"} "Toggle server>user async broadcast push loop"]] + [:p + [:button#btn5 {:type "button"} "Disconnect"] + [:button#btn6 {:type "button"} "Reconnect"]] ;; [:p [:strong "Step 2: "] " observe std-out (for server output) and below (for client output):"] [:textarea#output {:style "width: 100%; height: 200px;"}]