generated from FiV0/clj-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
165 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<configuration debug="false"> | ||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>test.log</file> | ||
<append>true</append> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="user" level="ALL" /> | ||
|
||
<!-- Show debug logs that originate from our namespace --> | ||
<property name="level" value="DEBUG"/> | ||
<logger name="io.dbme" level="${level}"/> | ||
|
||
<root level="DEBUG"> | ||
<appender-ref ref="CONSOLE"/> | ||
<!-- <appender-ref ref="FILE"/> --> | ||
</root> | ||
</configuration> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
(ns io.dbme.client | ||
(:require [reagent.dom])) | ||
(:require [io.dbme.frontend.events] | ||
[io.dbme.frontend.socket :as socket] | ||
[io.dbme.frontend.subs] | ||
[lambdaisland.glogi :as log] | ||
[lambdaisland.glogi.console :as glogi-console] | ||
[re-frame.core :as rf] | ||
[reagent.dom])) | ||
|
||
(glogi-console/install!) | ||
|
||
(log/set-levels | ||
{:glogi/root :info ;; Set a root logger level, this will be inherited by all loggers | ||
;; 'my.app.thing :trace ;; Some namespaces you might want detailed logging | ||
}) | ||
|
||
(defn connect-button [] | ||
[:input {:type :button | ||
:value "Connect" | ||
:disabled @(rf/subscribe [:app/connected]) | ||
:on-click #(rf/dispatch [:app/connect])}]) | ||
|
||
(defn app [] | ||
[:h2 "Hello from clojurescript!"]) | ||
[:div | ||
[connect-button] | ||
[:h2 | ||
(str @(rf/subscribe [:app/data]))]]) | ||
|
||
;; start is called by init and after code reloading finishes | ||
(defn ^:dev/after-load start [] | ||
(defn ^:dev/after-load start! [] | ||
(js/console.log "start") | ||
(rf/dispatch-sync [:app/init]) | ||
;; In case you immediatly want to create a connection | ||
;; (socket/create-client!) | ||
;; (socket/start-router!) | ||
(reagent.dom/render [app] (js/document.getElementById "app"))) | ||
|
||
(defn ^:export init [] | ||
;; init is called ONCE when the page loads | ||
;; this is called in the index.html and must be exported | ||
;; so it is available even in :advanced release builds | ||
(js/console.log "init") | ||
(start)) | ||
(start!)) | ||
|
||
;; this is called before any code is reloaded | ||
(defn ^:dev/before-load stop [] | ||
(js/console.log "stop")) | ||
(js/console.log "stop") | ||
(socket/stop-router!)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(ns io.dbme.frontend.events | ||
(:require [re-frame.core :as rf] | ||
[io.dbme.frontend.socket :as socket])) | ||
|
||
(rf/reg-event-db | ||
:app/init | ||
(fn [_ _] | ||
{:connected false | ||
:data {:initial :data}})) | ||
|
||
(rf/reg-event-db | ||
:app/connected | ||
(fn [db [_ value]] | ||
(assoc-in db [:connected] value))) | ||
|
||
(rf/reg-event-db | ||
:app/set-data | ||
(fn [db [_ data]] | ||
(assoc-in db [:data] data))) | ||
|
||
(rf/reg-event-fx | ||
:app/connect | ||
(fn [_ _] | ||
(socket/start!) | ||
{:dispatch [:app/connected true]})) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(ns io.dbme.frontend.handlers | ||
(:require [re-frame.core :as rf] | ||
[lambdaisland.glogc :as log])) | ||
|
||
(defmulti -event-msg-handler :id) | ||
|
||
(defn event-msg-handler | ||
[{:as ev-msg :keys [id ?data event]}] | ||
(-event-msg-handler ev-msg)) | ||
|
||
(defmethod -event-msg-handler :default | ||
[{:keys [event]}] | ||
(log/info :unhandled-event event)) | ||
|
||
(defmethod -event-msg-handler :chsk/recv | ||
[{:keys [?data]}] | ||
(let [[event-type data] ?data] | ||
(rf/dispatch [:app/set-data data]) | ||
(log/info :push-event data))) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(ns io.dbme.frontend.socket | ||
(:require [taoensso.sente :as sente] | ||
[taoensso.sente.packers.transit :as sente-transit] | ||
[io.dbme.frontend.handlers :as handlers])) | ||
|
||
(def router_ (atom nil)) | ||
|
||
(def ch-chsk (atom nil)) | ||
(def chsk-send! (atom nil)) | ||
(def chsk-state (atom nil)) | ||
|
||
(def config {:type :auto | ||
:packer :edn #_(sente-transit/get-transit-packer) ;:edn | ||
:protocol :http | ||
:host "localhost" | ||
:port 5000}) | ||
|
||
(defn state-watcher [_key _atom _old-state new-state] | ||
(.warn js/console "New state" new-state)) | ||
|
||
(defn create-client! [] | ||
(let [{:keys [ch-recv send-fn state]} (sente/make-channel-socket-client! "/chsk" nil config)] | ||
(reset! ch-chsk ch-recv) | ||
(reset! chsk-send! send-fn) | ||
(add-watch state :state-watcher state-watcher))) | ||
|
||
(defn stop-router! [] | ||
(when-let [stop-f @router_] (stop-f))) | ||
|
||
(defn start-router! [] | ||
(stop-router!) | ||
(reset! router_ (sente/start-client-chsk-router! @ch-chsk handlers/event-msg-handler))) | ||
|
||
(defn start! [] | ||
(create-client!) | ||
(start-router!)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(ns io.dbme.frontend.subs | ||
(:require [re-frame.core :as rf])) | ||
|
||
(rf/reg-sub | ||
:app/data | ||
(fn [db ] | ||
(get-in db [:data]))) | ||
|
||
(rf/reg-sub | ||
:app/connected | ||
(fn [db _] | ||
(true? (get-in db [:connected])))) |
This file contains 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
This file contains 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