Skip to content

Commit

Permalink
Revert "Only enable within-string diffing when selected."
Browse files Browse the repository at this point in the history
This reverts commit 6d28880.
  • Loading branch information
alysbrooks committed Jun 10, 2023
1 parent 6d28880 commit 5a3c15a
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions src/lambdaisland/deep_diff2/diff_impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,6 @@
(diff-seq-insertions ins)
(into []))))

(defn diff-string [exp act]
(->> (diff-seq exp act)
(map #(if (char? %) {:= %} %))
(partition-by (comp first keys))
(map (fn [[first-element :as coll]]
(let [head (first (keys first-element))
contents (mapcat vals coll)]
{head (apply str contents) })
)))
)

(defn diff-set [exp act]
(into
(into #{}
Expand Down Expand Up @@ -142,7 +131,7 @@
exp-ks))))

(defn primitive? [x]
(or (number? x) (boolean? x) (inst? x) (keyword? x) (symbol? x)))
(or (number? x) (string? x) (boolean? x) (inst? x) (keyword? x) (symbol? x)))

(defn diff-atom [exp act]
(if (= exp act)
Expand All @@ -162,30 +151,23 @@
(defn array? [x]
(and x (.isArray (class x)))))

(defn diff
([exp act]
(diff exp act {}))
([exp act {:keys [diff-strings?] :as _opts}]
(cond
(nil? exp)
(diff-atom exp act)

(and (diffable? exp)
(= (data/equality-partition exp) (data/equality-partition act)))
(diff-similar exp act)
(defn diff [exp act]
(cond
(nil? exp)
(diff-atom exp act)

(array? exp)
(diff-seq exp act)
(and (diffable? exp)
(= (data/equality-partition exp) (data/equality-partition act)))
(diff-similar exp act)

(record? exp)
(diff-map exp act)
(array? exp)
(diff-seq exp act)

(and diff-strings?
(string? exp))
(diff-string exp act)
(record? exp)
(diff-map exp act)

:else
(diff-atom exp act))))
:else
(diff-atom exp act)))

(extend-protocol Diff
#?(:clj java.util.Set :cljs cljs.core/PersistentHashSet)
Expand Down

0 comments on commit 5a3c15a

Please sign in to comment.