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
12 changed files
with
203 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
((nil . ((cider-clojure-cli-global-options . "-A:dev:test:build") | ||
(cider-preferred-build-tool . clojure-cli) | ||
(cider-default-cljs-repl . custom) | ||
(cider-custom-cljs-repl-init-form . "(do (user/cljs-repl) (user/browse 8280))") | ||
(cider-redirect-server-output-to-repl . t) | ||
(cider-repl-display-help-banner . nil) | ||
(clojure-toplevel-inside-comment-form . t)))) | ||
(clojure-toplevel-inside-comment-form . t) | ||
(eval . (progn | ||
(make-variable-buffer-local 'cider-jack-in-nrepl-middlewares) | ||
(add-to-list 'cider-jack-in-nrepl-middlewares "shadow.cljs.devtools.server.nrepl/middleware"))) ))) |
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ target | |
yarn.lock | ||
node_modules/ | ||
.DS_Store | ||
resources/public/ui | ||
resources/public/js | ||
.store | ||
out | ||
.#* |
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 |
---|---|---|
@@ -1 +1,16 @@ | ||
(ns user) | ||
(ns user | ||
(:require [clojure.java.browse :as browse] | ||
[shadow.cljs.devtools.api :as shadow] | ||
[shadow.cljs.devtools.server :as server])) | ||
|
||
(defn cljs-repl | ||
"Connects to a given build-id. Defaults to `:app`." | ||
([] | ||
(cljs-repl :app)) | ||
([build-id] | ||
(server/start!) | ||
(shadow/watch build-id) | ||
(shadow/nrepl-select build-id))) | ||
|
||
(defn browse [port] | ||
(browse/browse-url (str "http://localhost:" port))) |
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,15 @@ | ||
{ | ||
"name": "dbme", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"react": "^16.13.0", | ||
"react-dom": "^16.13.0", | ||
"react-scripts": "2.1.1", | ||
"shadow-cljs": "^2.11.5", | ||
"tailwindcss": "^2.2.16" | ||
}, | ||
"engines": { | ||
"node": ">=10" | ||
} | ||
} |
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,14 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="description" content=""> | ||
<title>sente example</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="text/javascript" src="/js/compiled/app.js"></script> | ||
<script>io.dbme.client.init()</script> | ||
</body> | ||
</html> |
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 @@ | ||
{:deps | ||
{:aliases [:dev]} | ||
|
||
:builds | ||
{:app | ||
{:target :browser | ||
|
||
:modules {:app {:entries [io.dbme.client] | ||
;; :preloads [devtools.preload] | ||
}} | ||
|
||
:output-dir "resources/public/js/compiled" | ||
:asset-path "/js/compiled" | ||
:dev {:compiler-options {:devcards true}} | ||
:release {:compiler-options {:warnings-as-errors true | ||
:warnings {:redef-in-file false} | ||
:closure-defines {goog.DEBUG false | ||
goog.debug.LOGGING_ENABLED true}}} | ||
:js-options {:resolve | ||
{"react" {:export-globals ["React"]} | ||
"react-dom" {:export-globals ["ReactDOM"]}}} | ||
:devtools {:repl-pprint true}}} | ||
|
||
;; TODO understand | ||
:cache-blockers #{}} |
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,21 @@ | ||
(ns io.dbme.client | ||
(:require [reagent.dom])) | ||
|
||
(defn app [] | ||
[:h2 "Hello from clojurescript!"]) | ||
|
||
;; start is called by init and after code reloading finishes | ||
(defn ^:dev/after-load start [] | ||
(js/console.log "start") | ||
(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)) | ||
|
||
;; this is called before any code is reloaded | ||
(defn ^:dev/before-load stop [] | ||
(js/console.log "stop")) |
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,11 @@ | ||
(ns io.dbme.handlers) | ||
|
||
(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 id ?data ring-req ?reply-fn send-fn]}] | ||
(println (str "Unhandled event: %s" event))) |
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,24 @@ | ||
(ns io.dbme.router | ||
(:require [compojure.core :as comp :refer (defroutes GET POST)] | ||
[compojure.route :as route] | ||
[io.dbme.handlers :as handlers] | ||
[io.dbme.socket :as socket] | ||
[ring.middleware.defaults] | ||
[ring.util.response :as response] | ||
[taoensso.sente :as sente])) | ||
|
||
(defroutes ring-routes | ||
(GET "/" _ring-req (response/content-type (response/resource-response "index.html") "text/html")) | ||
(GET "/chsk" ring-req (socket/ring-ajax-get-or-ws-handshake ring-req)) | ||
(POST "/chsk" ring-req (socket/ring-ajax-post ring-req)) | ||
(route/resources "/") | ||
(route/not-found "Not found")) | ||
|
||
(defonce router_ (atom nil)) | ||
|
||
(defn stop! [] | ||
(when-let [stop-fn @router_] (stop-fn))) | ||
|
||
(defn start! [] | ||
(stop!) | ||
(reset! router_ (sente/start-server-chsk-router! socket/ch-chsk handlers/event-msg-handler))) |
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.server | ||
(:require [io.dbme.router :as router] | ||
[org.httpkit.server :as http-kit] | ||
[ring.middleware.defaults :as middleware])) | ||
|
||
(def main-ring-handler | ||
(middleware/wrap-defaults router/ring-routes middleware/site-defaults)) | ||
|
||
(defonce web-server_ (atom nil)) | ||
|
||
(defn stop-server! [] | ||
(when-let [stop-fn @web-server_] (stop-fn))) | ||
|
||
(defn start-server! [port] | ||
(stop-server!) | ||
(let [ring-handler (var main-ring-handler) | ||
[port stop-fn] | ||
(let [stop-fn (http-kit/run-server ring-handler {:port port})] | ||
[(:local-port (meta stop-fn)) (fn [] (stop-fn :timeout 100))])] | ||
(println (str "Running at port " port)) | ||
(reset! web-server_ stop-fn))) | ||
|
||
(defn start! [] | ||
(router/start!) | ||
(start-server! 5000) | ||
#_(socket/start-example-broadcaster!)) | ||
|
||
(defn stop! [] | ||
(router/stop!) | ||
(stop-server!)) | ||
|
||
(defn -main [] | ||
(start!)) | ||
|
||
(comment | ||
(start!)) |
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,14 @@ | ||
(ns io.dbme.socket | ||
(:require [taoensso.sente :as sente] | ||
[taoensso.sente.server-adapters.http-kit :as http-kit] | ||
[taoensso.sente.packers.transit :as sente-transit])) | ||
|
||
(let [chsk-server (sente/make-channel-socket-server! (http-kit/get-sch-adapter) | ||
{:packer (sente-transit/get-transit-packer) ;:edn | ||
:csrf-token-fn nil}) | ||
{:keys [ch-recv send-fn connected-uids ajax-post-fn ajax-get-or-ws-handshake-fn]} chsk-server] | ||
(def ring-ajax-post ajax-post-fn) | ||
(def ring-ajax-get-or-ws-handshake ajax-get-or-ws-handshake-fn) | ||
(def ch-chsk ch-recv) | ||
(def chsk-send! send-fn) | ||
(def connected-uids connected-uids)) |