-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstores.cljs
37 lines (27 loc) · 894 Bytes
/
stores.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns todomvc.stores
(:require [clojure.spec.alpha :as s]
[datascript.core :as d]
[mook.core :as m]
[todomvc.boundaries.ui :as b-ui]))
(extend-type datascript.db/DB
m/Watchable
(m/listen! [this key f]
(d/listen! this key (fn watch-changes [{:keys [db-after] :as _transaction-data}]
(f {::m/new-state db-after}))))
(m/unlisten! [this key]
(d/unlisten! this key)))
;; ---
(s/def ::local-store map?)
(s/def ::local-store* #(satisfies? cljs.core/IAtom %))
(defonce app-db* (d/create-conn {}))
;; ---
(s/def ::app-db d/db?)
(s/def ::app-db* d/conn?)
(defonce local-store* (atom {::b-ui/active-filter :all
;; :local/counter 0
}))
;; ---
(s/def ::stores*
(s/keys :req [::local-store* ::app-db*]))
(s/def ::states
(s/keys :req [::local-store ::app-db]))