Skip to content

Instantly share code, notes, and snippets.

@nblumoe
Last active December 18, 2015 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nblumoe/e937103389d0173f887f to your computer and use it in GitHub Desktop.
Save nblumoe/e937103389d0173f887f to your computer and use it in GitHub Desktop.
;; example for novelty:
{:user/verify {:db/id 1234 :being-verified false :verification-error :credentials-invalid}}
(defn merge-tree [old-state novelty]
(cond
(:user/verify novelty)
(let [novelty-props (:user/verify novelty)]
(update-in old-state [:users/by-id (:db/id novelty-props)] merge (dissoc novelty-props :db/id)))
(map? old-state)
(merge old-state novelty)
:else
novelty))
(defmethod mutate 'user/verify
[{:as env :keys [ref state reconciler]} _ _]
{:value {:keys [:users/list]} ;; problably not needed, users have Ident
:action #(swap! state update-in ref merge {:being-verified true}) ;; triggering local change
:rest-remote true}) ;; response gets merged into app-state, but no re-rendering is triggered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment