Skip to content

Commit

Permalink
pass db to hydrate-bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
bamarco committed Jun 9, 2019
1 parent 65b2406 commit 4fad84e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/cljc/dat/sync/peer.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(ns dat.sync.client
"# Datsync client API"
#?(:cljs (:require-macros [cljs.core.async.macros :as async-macros :refer [go go-loop]]))
(:require #?@(:clj [[clojure.core.async :as async :refer [go go-loop]]]
:cljs [[cljs.core.async :as async]])
[dat.remote :as remote]
[dat.reactor :as reactor]
[dat.reactor.dispatcher :as dispatcher]
[dat.sync.utils :as utils]
[datascript.core :as d]
[com.stuartsierra.component :as component]
[taoensso.timbre :as log]))

(defrecord Datsync [dispatcher remote]
component/Lifecycle
(start [component]
(let [remote-chan (remote/event-chan remote)]
(log/info "Starting Datsync component")
(dispatcher/dispatch! dispatcher [::merge-schema base-schema])
;; This should get triggered by successful connection to the websocket
(log/info "Dispatched schema changes")
(go-loop []
(let [event (async/<! remote-chan)]
(dispatcher/dispatch! dispatcher event)
(recur)))
component))
(stop [component]
component))


(defn new-datsync []
(map->Datsync {}))
2 changes: 1 addition & 1 deletion src/dat/sync/client.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@
;; TODO Generalize this to keep the things we might have already created client side. Reapply the
;; indexing function?
(map? data) (let [_ (log/info "processing map form bootstrap")
new-db (dat.sync/hydrate-bootstrap data)
new-db (dat.sync/hydrate-bootstrap db data)
_ (log/info "bootstrap eav index ingested as db")]
new-db)
;; Otherwise treat it as a tx
Expand Down
15 changes: 15 additions & 0 deletions test/cljc/dat/sync/test/peer.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns dat.sync.test.peer
#? (:cljs (:require-macros [cljs.test :refer (is deftest testing)]))
(:require
[datascript.core :as d]
#?(:clj [clojure.test :refer :all]
:cljs [cljs.test])))

(def schema {})

(deftest test-client
(let [conn (d/create-conn schema)
_ (sync! conn "server.uri")
txes [[:db/add [:animal/name :bobo] :animal/mouth :teeth]]]
(sync/transact! server-conn txes)
(is conn)))

0 comments on commit 4fad84e

Please sign in to comment.