Skip to content

Instantly share code, notes, and snippets.

@dupuchba
Created March 16, 2017 19:35
Show Gist options
  • Save dupuchba/b137ee3339eb8277e372b9cc30ae20dd to your computer and use it in GitHub Desktop.
Save dupuchba/b137ee3339eb8277e372b9cc30ae20dd to your computer and use it in GitHub Desktop.
(defn move-element [state from to element]
(letfn [(remove* [elements ref]
(into [] (remove #{ref} elements)))
(add* [elements ref]
(into [] (cond-> elements
(not (some #{ref} elements)) (conj ref))))]
(-> state
(update-in (conj from :elements) remove* element)
(update-in (conj to :elements) add* element))))
(defmethod mutate 'element/drop
[{:keys [state]} _ {:keys [from to element]}]
{:value {:keys [element from to]}
:action (fn []
(swap! state move-element from to element))})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment