|
97 | 97 | (diff-seq-insertions ins) |
98 | 98 | (into [])))) |
99 | 99 |
|
100 | | -(defn- val-type [val] |
| 100 | +#?(:clj (defn- val-type [val] |
101 | 101 | (let [t (type val)] |
102 | 102 | (if (class? t) |
103 | 103 | (symbol (.getName ^Class t)) |
104 | | - t))) |
| 104 | + t)))) |
105 | 105 |
|
106 | 106 | (defn- diff-map [exp act] |
107 | 107 | (first |
|
136 | 136 | (diff-similar exp act) |
137 | 137 | (diff-atom exp act))) |
138 | 138 |
|
139 | | -(extend nil |
140 | | - Diff |
141 | | - {:diff-similar diff-atom}) |
142 | | - |
143 | | -(extend Object |
144 | | - Diff |
145 | | - {:diff-similar (fn [exp act] |
146 | | - (if (.isArray (.getClass ^Object exp)) |
147 | | - (diff-seq exp act) |
148 | | - (diff-atom exp act)))}) |
| 139 | +#?(:clj (extend nil |
| 140 | + Diff |
| 141 | + {:diff-similar diff-atom}) |
| 142 | + :cljs (extend-type nil ;; I am not pretty sure about this. Lets wait for unit tests |
| 143 | + Diff |
| 144 | + {:diff-similar diff-atom})) |
| 145 | + |
| 146 | +#?(:clj (extend Object |
| 147 | + Diff |
| 148 | + {:diff-similar (fn [exp act] |
| 149 | + (if (.isArray (.getClass ^Object exp)) |
| 150 | + (diff-seq exp act) |
| 151 | + (diff-atom exp act)))}) |
| 152 | + :cljs (extend-type object |
| 153 | + Diff |
| 154 | + {:diff-similar (fn [exp act] |
| 155 | + (if (array? exp) |
| 156 | + (diff-seq exp act) |
| 157 | + (diff-atom exp act)))})) |
149 | 158 |
|
150 | 159 | (extend-protocol Diff |
151 | | - java.util.List |
| 160 | + #?(:clj java.util.List |
| 161 | + :cljs cljs.core.list) |
152 | 162 | (diff-similar [exp act] (diff-seq exp act)) |
153 | 163 |
|
154 | | - java.util.Set |
| 164 | + #?(:clj java.util.Set |
| 165 | + :cljs cljs.core.set) |
155 | 166 | (diff-similar [exp act] |
156 | 167 | (let [exp-seq (seq exp) |
157 | 168 | act-seq (seq act)] |
158 | 169 | (set (diff-seq exp-seq (concat (filter act exp-seq) |
159 | 170 | (remove exp act-seq)))))) |
160 | 171 |
|
161 | | - java.util.Map |
| 172 | + #?(:clj java.util.Map |
| 173 | + :cljs cljs.core.map) |
162 | 174 | (diff-similar [exp act] (diff-map exp act))) |
163 | 175 |
|
164 | 176 | (extend-protocol Undiff |
165 | | - java.util.List |
| 177 | + #?(:clj java.util.List |
| 178 | + :cljs cljs.core.list) |
166 | 179 | (left-undiff [s] (map left-undiff (remove #(instance? Insertion %) s))) |
167 | 180 | (right-undiff [s] (map right-undiff (remove #(instance? Deletion %) s))) |
168 | 181 |
|
169 | | - java.util.Set |
| 182 | + #?(:clj java.util.Set |
| 183 | + :cljs cljs.core.set) |
170 | 184 | (left-undiff [s] (set (left-undiff (seq s)))) |
171 | 185 | (right-undiff [s] (set (right-undiff (seq s)))) |
172 | 186 |
|
173 | | - java.util.Map |
| 187 | + #?(:clj java.util.Map |
| 188 | + :cljs cljs.core.map) |
174 | 189 | (left-undiff [m] |
175 | 190 | (into {} |
176 | 191 | (comp (remove #(instance? Insertion (key %))) |
|
192 | 207 | Deletion |
193 | 208 | (left-undiff [m] (get m :-))) |
194 | 209 |
|
195 | | -(extend nil Undiff {:left-undiff identity :right-undiff identity}) |
196 | | -(extend Object Undiff {:left-undiff identity :right-undiff identity}) |
| 210 | +#?(:clj (extend nil Undiff {:left-undiff identity :right-undiff identity}) |
| 211 | + :cljs (extend-type nil Undiff {:left-undiff identity :right-undiff identity})) |
| 212 | + |
| 213 | +$?(:clj (extend Object Undiff {:left-undiff identity :right-undiff identity}) |
| 214 | + :cljs (extend-type object Undiff {:left-undiff identity :right-undiff identity})) |
0 commit comments