Created
May 27, 2014 07:42
-
-
Save txrev319/50ac3fbba4251436abc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)] | |
ans))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment