Skip to content

Instantly share code, notes, and snippets.

@onetom
Created June 5, 2015 01:59
Show Gist options
  • Save onetom/43e4009dd8fa124ce399 to your computer and use it in GitHub Desktop.
Save onetom/43e4009dd8fa124ce399 to your computer and use it in GitHub Desktop.
Function within `cell-let` fails with Hoplon6
(defelem cell-let-problem [{:keys [data]}]
(cell-let [{:keys [title]} data
fun #(str title " - " title)
double-title (fun)]
(div :text double-title)))
(cell-let-problem :data (cell {:title "cell-let test"}))
# Uncaught TypeError: fun.call is not a function
@micha
Copy link

micha commented Jun 5, 2015

(defelem cell-let-problem [{:keys [data]}]
  (cell-let [{:keys [title]} data]
    (div :text (cell= (str title " - " title)))))

(cell-let-problem :data (cell {:title "cell-let test"}))

@onetom
Copy link
Author

onetom commented Jun 5, 2015

(defelem app-profile [{:keys [app] :as attrs}]
  (cell-let
    [
     {:keys [price categories version release-date languages brand currency platform]} app
     apple? (= "apple" platform)

     format-values #(-> %
                        (assoc :price (as-currency currency price))
                        (assoc :categories (as-tags categories))
                        (assoc :version (as-str version))
                        (assoc :brand (as-str brand))
                        (assoc :release-date (as-date release-date))
                        (assoc :languages (as-tags languages)))

     fields-to-show (concat
                      [:price :categories :version]
                      (when apple? [:release-date :languages])
                      [:brand])
     select-fields-to-show #(select-keys % fields-to-show)

     field-name
     {
      :price "Price"
      :categories "Categories"
      :version "Version"
      :release-date "Release date"
      :languages "Languages"
      :brand "Brand"}

     label-fields #(zipmap (map field-name (keys %)) (vals %))

     app-summary (-> app   format-values   select-fields-to-show   label-fields)

     store-badge (if apple? "/images/apple-store.png" "/images/google-play.png")
     ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment