You would have to use a Clojure macro to abstract this, which in turn will call
a paramaterised function
On Sunday, March 1, 2015 at 4:24:18 PM UTC+1, Sven Richter wrote:
> Hi,
>
> I have several functions that do an async request to the server. There are
> constraints for this functions.
>
> 1. Only send an request if some value is not empty
> 2. Disable and enable some button before and after the request.
>
> A function might look like this:
>
> (defn add-group []
> (let [g-name (h/get-value "add-group-input")
> ;repetitive get element
> clicked-button (h/get-elem "add-group-btn")]
> ;repetitive only send when not empty
> (when (not-empty g-name)
> (go (let [[ok uuid] (<! (h/post-async "/admin/group/add" {:name g-name}
> clicked-button))]
> (if ok (do (swap! app-state update-in [:groups] conj {:name g-name
> :uuid uuid})
> (set-user-selection-hidden-state (:groups @app-state))
> (h/show-success-message "notification-div" "Group
> Added"))
> (h/show-error-message "notification-div"))
> ;repetitive remove disbled attribute
> (.removeAttribute clicked-button "disabled"))))))
>
> How would I put this repeating code into a function? Or would I need to write
> a macro for this kind of repetition?
>
> Best Regards,
> Sven
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.