|
9 | 9 | [me.tonsky.persistent-sorted-set :as set] |
10 | 10 | [me.tonsky.persistent-sorted-set.arrays :as arrays]) |
11 | 11 | #?(:clj (:import clojure.lang.IFn$OOL)) |
12 | | - #?(:cljs (:require-macros [datascript.db :refer [case-tree combine-cmp declare+ defn+ defcomp defrecord-updatable int-compare validate-attr validate-val]])) |
| 12 | + #?(:cljs (:require-macros [datascript.db :refer [case-tree combine-cmp defn+ defcomp defrecord-updatable int-compare validate-attr validate-val]])) |
13 | 13 | (:refer-clojure :exclude [seqable? #?(:clj update)])) |
14 | 14 |
|
15 | 15 | #?(:clj (set! *warn-on-reflection* true)) |
|
80 | 80 | 'number (assoc meta :tag clojure.core$long) |
81 | 81 | meta)))) |
82 | 82 |
|
83 | | -#?(:clj |
84 | | - (defmacro declare+ |
85 | | - "Same idea as `declare`, but allows to declare type hints and arglists. |
86 | | - This allows CLJS to generate more efficient code when calling this fn |
87 | | - before it’s declared" |
88 | | - [name & arglists] |
89 | | - (let [name' (vary-meta name patch-tag (cljs-env? &env)) |
90 | | - bodies (map #(list % `(throw (ex-info (str "Not implemented: (" ~name (clojure.string/join " " ~%)) {}))) arglists)] |
91 | | - `(defn ~name' ~@bodies)))) |
92 | | - |
93 | 83 | #?(:clj |
94 | 84 | (defmacro defn+ |
95 | | - "Version of `defn` that works with `declare+`. CLJS really don’t like |
96 | | - :declared metadata on vars (generates less efficient code), but it |
97 | | - needs it to skip warnings. So we redefine first with ^:declared |
98 | | - and empty implementation, and then immediately redefine again without ^:declared. |
99 | | - This way both `declare+`-d and `defn+`-d versions have no ^:declared meta, |
100 | | - thus allowing CLJS to generate direct invocations and see type hints." |
| 85 | + "CLJS really don’t like :declared metadata on vars (generates less |
| 86 | + efficient code), but it needs it to skip warnings. So we redefine |
| 87 | + first with ^:declared and empty implementation, and then immediately |
| 88 | + redefine again without ^:declared. This way both `declare` and `defn+` |
| 89 | + versions have no ^:declared meta, thus allowing CLJS to generate direct |
| 90 | + invocations and see type hints." |
101 | 91 | [name & rest] |
102 | 92 | (let [name' (vary-meta name patch-tag (cljs-env? &env)) |
103 | 93 | arglists (if (vector? (first rest)) |
|
163 | 153 |
|
164 | 154 | ;; ---------------------------------------------------------------------------- |
165 | 155 |
|
166 | | -#?(:cljs (declare+ ^number hash-datom [d]) :clj (declare hash-datom)) |
| 156 | +#?(:clj (declare hash-datom) |
| 157 | + :cljs (defn ^number hash-datom [d])) |
167 | 158 |
|
168 | | -#?(:cljs (declare+ ^boolean equiv-datom [d o]) :clj (declare equiv-datom)) |
| 159 | +#?(:clj (declare equiv-datom) |
| 160 | + :cljs (defn ^boolean equiv-datom [d o])) |
169 | 161 |
|
170 | | -#?(:cljs (declare+ seq-datom [d]) :clj (declare seq-datom)) |
| 162 | +#?(:clj (declare seq-datom) |
| 163 | + :cljs (defn seq-datom [d])) |
171 | 164 |
|
172 | | -#?(:cljs (declare+ nth-datom [d i] [d i not-found]) :clj (declare nth-datom)) |
| 165 | +#?(:clj (declare nth-datom) |
| 166 | + :cljs (defn nth-datom ([d i]) ([d i not-found]))) |
173 | 167 |
|
174 | | -#?(:cljs (declare+ assoc-datom [d k v]) :clj (declare assoc-datom)) |
| 168 | +#?(:clj (declare assoc-datom) |
| 169 | + :cljs (defn assoc-datom [d k v])) |
175 | 170 |
|
176 | | -#?(:cljs (declare+ val-at-datom [d k not-found]) :clj (declare val-at-datom)) |
| 171 | +#?(:clj (declare val-at-datom) |
| 172 | + :cljs (defn val-at-datom [d k not-found])) |
177 | 173 |
|
178 | 174 | (defprotocol IDatom |
179 | 175 | (datom-tx [this]) |
|
409 | 405 | #?(:clj (. clojure.lang.Util (hasheq x)) |
410 | 406 | :cljs (hash x))) |
411 | 407 |
|
412 | | -#?(:cljs (declare+ ^number value-compare [x y]) :clj (declare value-compare)) |
| 408 | +#?(:clj (declare value-compare) |
| 409 | + :cljs (defn ^number value-compare [x y])) |
413 | 410 |
|
414 | 411 | (defn- seq-compare [xs ys] |
415 | 412 | (let [cx (count xs) |
|
584 | 581 |
|
585 | 582 | ;; ---------------------------------------------------------------------------- |
586 | 583 |
|
587 | | -#?(:cljs (declare+ ^number hash-db [db]) :clj (declare hash-db)) |
| 584 | +#?(:clj (declare hash-db) |
| 585 | + :cljs (defn ^number hash-db [db])) |
588 | 586 |
|
589 | | -#?(:cljs (declare+ ^number hash-fdb [db]) :clj (declare hash-fdb)) |
| 587 | +#?(:clj (declare hash-fdb) |
| 588 | + :cljs (defn ^number hash-fdb [db])) |
590 | 589 |
|
591 | | -#?(:cljs (declare+ ^boolean equiv-db [db other]) :clj (declare equiv-db)) |
| 590 | +#?(:clj (declare equiv-db) |
| 591 | + :cljs (defn ^boolean equiv-db [db other])) |
592 | 592 |
|
593 | | -#?(:cljs (declare+ restore-db [keys]) :clj (declare restore-db)) |
| 593 | +#?(:clj (declare restore-db) |
| 594 | + :cljs (defn restore-db [keys])) |
594 | 595 |
|
595 | | -#?(:cljs (declare+ ^boolean indexing? [db attr]) :clj (declare indexing?)) |
| 596 | +#?(:clj (declare indexing?) |
| 597 | + :cljs (defn ^boolean indexing? [db attr])) |
596 | 598 |
|
597 | | -#?(:cljs |
598 | | - (declare+ pr-db [db w opts])) |
| 599 | +#?(:cljs (defn pr-db [db w opts])) |
599 | 600 |
|
600 | | -#?(:cljs (declare+ resolve-datom [db e a v t default-e default-tx]) :clj (declare resolve-datom)) |
| 601 | +#?(:clj (declare resolve-datom) |
| 602 | + :cljs (defn resolve-datom [db e a v t default-e default-tx])) |
601 | 603 |
|
602 | | -#?(:cljs (declare+ components->pattern [db index c0 c1 c2 c3 default-e default-tx]) :clj (declare components->pattern)) |
| 604 | +#?(:clj (declare components->pattern) |
| 605 | + :cljs (defn components->pattern [db index c0 c1 c2 c3 default-e default-tx])) |
603 | 606 |
|
604 | 607 | ;;;;;;;;;; Fast validation |
605 | 608 |
|
|
1122 | 1125 |
|
1123 | 1126 | ;; ---------------------------------------------------------------------------- |
1124 | 1127 |
|
1125 | | -#?(:cljs (declare+ ^number entid-strict [db eid]) :clj (declare entid-strict)) |
| 1128 | +#?(:clj (declare entid-strict) |
| 1129 | + :cljs (defn ^number entid-strict [db eid])) |
1126 | 1130 |
|
1127 | | -#?(:cljs (declare+ ^boolean ref? [db attr]) :clj (declare ref?)) |
| 1131 | +#?(:clj (declare ref?) |
| 1132 | + :cljs (defn ^boolean ref? [db attr])) |
1128 | 1133 |
|
1129 | 1134 | (defn+ resolve-datom [db e a v t default-e default-tx] |
1130 | 1135 | (when (some? a) |
|
1619 | 1624 | (filter (fn [^Datom d] (component? db (.-a d)))) |
1620 | 1625 | (map (fn [^Datom d] [:db.fn/retractEntity (.-v d)]))) datoms)) |
1621 | 1626 |
|
1622 | | -#?(:cljs (declare+ transact-tx-data-impl [initial-report initial-es]) :clj (declare transact-tx-data-impl)) |
| 1627 | +#?(:clj (declare transact-tx-data-impl) |
| 1628 | + :cljs (defn transact-tx-data-impl [initial-report initial-es])) |
1623 | 1629 |
|
1624 | 1630 | (defn- retry-with-tempid [initial-report report es tempid upserted-eid] |
1625 | 1631 | (if-some [eid (get (::upserted-tempids initial-report) tempid)] |
|
0 commit comments