Skip to content

Commit

Permalink
fix op-id
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyong committed Nov 24, 2017
1 parent be745a7 commit 9814264
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/coir.edn

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions app/src/app/comp/container.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
(if (= :watching (:name router))
(cursor-> :watching comp-watching states (:data router) theme)
(comp-login states))))
(comp-inspect "Session" (:user store) style-inspector)
(comment
comp-inspect
"Router data"
(get-in store [:router :data])
(merge style-inspector {:left 100}))
(comment comp-inspect "Session" (:user store) style-inspector)
(comment comp-inspect "Router data" states (merge style-inspector {:left 100}))
(comp-messages (get-in store [:session :notifications]))))))
2 changes: 1 addition & 1 deletion server/coir.edn

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions server/src/server/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
["chalk" :as chalk]
["path" :as path]
["express" :as express]
["serve-index" :as serve-index])
["serve-index" :as serve-index]
["shortid" :as shortid])
(:require-macros [cljs.core.async.macros :refer [go-loop go]]))

(defonce *writer-db
Expand All @@ -26,14 +27,21 @@

(def global-configs (pick-configs (:configs @*writer-db)))

(defn dispatch! [op op-data sid op-id]
(comment .log js/console "Action" (str op) (clj->js op-data) sid op-id)
(defn dispatch! [op op-data sid]
(comment .log js/console "Action" (str op) (clj->js op-data) sid)
(comment .log js/console "Database:" (clj->js @*writer-db))
(cond
(= op :effect/save-files) (handle-files! @*writer-db global-configs dispatch! true)
(= op :effect/save-files)
(handle-files! @*writer-db global-configs #(dispatch! %1 %2 sid) true)
:else
(try
(let [new-db (updater @*writer-db op op-data sid op-id (.valueOf (js/Date.)))]
(let [new-db (updater
@*writer-db
op
op-data
sid
(.generate shortid)
(.valueOf (js/Date.)))]
(reset! *writer-db new-db))
(catch js/Error e (println (.red chalk e))))))

Expand Down
8 changes: 4 additions & 4 deletions server/src/server/network.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@
wss
"connection"
(fn [socket]
(let [sid (.generate shortid), op-id (.generate shortid)]
(on-action! :session/connect nil sid op-id)
(let [sid (.generate shortid)]
(on-action! :session/connect nil sid)
(swap! *registry assoc sid socket)
(println (.gray chalk (str "client connected: " sid)))
(.on
socket
"message"
(fn [rawData]
(let [action (reader/read-string rawData), [op op-data] action]
(on-action! op op-data sid op-id))))
(on-action! op op-data sid))))
(.on
socket
"close"
(fn []
(println (.gray chalk (str "client disconnected: " sid)))
(swap! *registry dissoc sid)
(on-action! :session/disconnect nil sid op-id))))))
(on-action! :session/disconnect nil sid))))))
(println
"Server started, please edit on"
(.blue chalk (str "http://cumulo-editor.cirru.org?port=" port))))))))))
Expand Down

0 comments on commit 9814264

Please sign in to comment.