|
25 | 25 |
|
26 | 26 | (defn- connect-to-self-hosted!
|
27 | 27 | [url]
|
28 |
| - (js/console.log "WS Client Connecting to:" url) |
| 28 | + (js/console.log "WSClient Connecting to:" url) |
29 | 29 | (when url
|
30 | 30 | (doto (js/WebSocket. url)
|
31 | 31 | (.addEventListener "open" open-handler)
|
|
240 | 240 | :db/valueType
|
241 | 241 | :db/unique}
|
242 | 242 | ;; attribute
|
243 |
| - (second %))) |
| 243 | + (:a %))) |
244 | 244 | ;; group by entity id
|
245 |
| - (group-by first) |
| 245 | + (group-by :e) |
246 | 246 | (reduce (fn [acc [entity-id datoms]]
|
| 247 | + (js/console.debug "reduce1:" (pr-str entity-id)) |
247 | 248 | (assoc acc entity-id
|
248 |
| - (reduce (fn [entity [_ a v]] |
| 249 | + (reduce (fn [entity {:keys [a v]}] |
249 | 250 | (assoc entity a
|
250 | 251 | (if (= :block/children a)
|
251 | 252 | (conj (:block/children entity #{})
|
|
263 | 264 | (js/console.debug "Received DB Dump")
|
264 | 265 | (let [entities (reconstruct-entities-from-db-dump datoms)]
|
265 | 266 | (js/console.debug "Reconstructed" (count entities) "entities")
|
266 |
| - (d/transact! db/dsdb entities) |
| 267 | + (rf/dispatch [:reset-conn (d/empty-db db/schema)]) |
| 268 | + (rf/dispatch [:transact entities]) |
267 | 269 | (rf/dispatch [:remote/last-seen-tx! last-tx])
|
| 270 | + (rf/dispatch [:db/sync]) |
| 271 | + (rf/dispatch [:remote/connected]) |
268 | 272 | (js/console.log "✅ Transacted DB dump. last-seen-tx" last-tx)))
|
269 | 273 |
|
270 | 274 |
|
|
311 | 315 | {:event/keys
|
312 | 316 | [id]} packet
|
313 | 317 | req-event (get @awaiting-response id)]
|
| 318 | + (js/console.log "message-handler" (pr-str packet)) |
314 | 319 | (if req-event
|
315 | 320 | (awaited-response-handler req-event packet)
|
316 | 321 | (server-event-handler packet))))
|
|
359 | 364 | component)))
|
360 | 365 |
|
361 | 366 |
|
| 367 | +;; TODO: password protection |
362 | 368 | (defn new-ws-client
|
363 | 369 | [url]
|
364 | 370 | (map->WSClient {:url url}))
|
|
0 commit comments