Skip to content

Instantly share code, notes, and snippets.

@currentoor
Created October 24, 2018 21:55
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 currentoor/8c482c1440ca0fb1dfae24a305fca070 to your computer and use it in GitHub Desktop.
Save currentoor/8c482c1440ca0fb1dfae24a305fca070 to your computer and use it in GitHub Desktop.
(defmutation add-n
[{:keys [n]}]
(action [{:keys [state]}]
(swap! state update :counter + n)))
;; This simulates the app state
(def st (atom {:counter 0}))
;; First arg is the env, second is the mutation name, third is the params
(fulcro.client.mutations/mutate {:state st} `add-n {:n 3})
;; => {:action #object[Function]}
(let [{:keys [action]} (fulcro.client.mutations/mutate {:state st} `add-n {:n 3}) ]
(action))
;; Now in tests you can verify the state has been updated
@st
;; => {:counter 3}
(defn run-mutation [sym params]
(let [{:keys [action]} (fulcro.client.mutations/mutate {:state st} sym params)]
(action)))
;; Same effect as the above code
(run-mutation `add-n {:n 3})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment