Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns doc.doc-diff
#+clj (:require [clojure.core.typed :as t])
#+cljs (:require-macros [cljs.core.typed :as t]))
(t/defalias Cmd (U Set-Attrs Set-Order Update-Child Swap-Child))
(t/defalias Cmds (t/Seq Cmd))
(t/defalias Set-Attrs
(HMap :mandatory {:tag (Value :set-attrs!)
:old-attrs (t/Map Any Any)
:new-attrs (t/Map Any Any)}))
(t/defalias Set-Order
(HMap :mandatory {:tag (Value :set-order!)
:old-order (t/Seq Any)
:new-order (t/Seq Any)}))
(t/defalias Update-Child
(HMap :mandatory {:tag (Value :update-child!)
:cmds Cmds}))
(t/defalias Swap-Child
(HMap :mandatory {:tag (Value :swap-child!)
:new-tag Any
:cmds Cmds}))
(t/defn> doc-diff--same-tag :- Any
[old-doc :- Any
new-doc :- Any]
(assert (= (:tag old-doc) (:tag new-doc)))
(if (identical? old-doc new-doc)
(t/let [cmds-atom :- (t/Atom1 Cmds) (atom '())
cmds :- Cmds @cmds-atom
ans :- Cmds (reverse cmds)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment