This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-29
Channels
- # babashka (4)
- # babashka-sci-dev (96)
- # beginners (79)
- # calva (26)
- # cider (5)
- # clerk (2)
- # clj-kondo (23)
- # clojars (14)
- # clojure (54)
- # clojure-europe (8)
- # clojure-sweden (3)
- # clojurescript (76)
- # datomic (12)
- # deps-new (6)
- # emacs (20)
- # events (3)
- # exercism (1)
- # fulcro (11)
- # funcool (12)
- # hugsql (14)
- # hyperfiddle (6)
- # kaocha (1)
- # lambdaisland (1)
- # lsp (22)
- # malli (1)
- # matcher-combinators (6)
- # nbb (6)
- # off-topic (128)
- # polylith (14)
- # re-frame (4)
- # reagent (1)
- # releases (4)
- # shadow-cljs (8)
- # tools-build (13)
- # tools-deps (13)
- # tree-sitter (5)
How to represent an array in clojurescript?
I'm confused because I don't understand why this works
(defn render-content []
(println "test rendering")
(println(. js/document -body))
(m/render (. js/document -body) (m "h1" "test"
(m "h1" "my epic header")
(m "h2" "my epic subheader"))))
Where m-render requires an arrayAnyone know why I can't get this to render?
(let my-pictures #js {:view (fn [] (
(m "main" #js {:class "container"}
(m "article"
(m "h1" #js {:role "button"} "My Name")
(m "h2" "My Pictures")))))})
(defn render-content []
(println "test rendering")
(println my-pictures)
(println(. js/document -body))
(m/mount (. js/document -body) my-pictures))
(defn init []
(.addEventListener js/document "DOMContentLoaded" render-content))
(let [my-pictures #js {:view (fn [] (m "main" #js {:class "container"}
(m "article"
(m "h1" #js {:role "button"} "My Name")
(m "h2" "My Pictures"))))}])
I'm not sure which I should use
The js is var
So I think def probably makes more sense
that fixed it with def
(defn render-content []
(let [my-pictures #js {:view (fn [] (m "main" #js {:class "container"}
(m "article"
(m "h1" #js {:role "button"} "My Name")
(m "h2" "My Pictures"))))}]
(println "test rendering")
(println my-pictures)
(println (. js/document -body))
(m/mount (. js/document -body) my-pictures)))
or
(def my-pictures #js {:view (fn [] (m "main" #js {:class "container"}
(m "article"
(m "h1" #js {:role "button"} "My Name")
(m "h2" "My Pictures"))))})
(defn render-content []
(println "test rendering")
(println my-pictures)
(println (. js/document -body))
(m/mount (. js/document -body) my-pictures))
that makes sense ty, do you recommend a specific scope over the other?
also any stuff you recommend for data structures?
if its only constructed once and takes no other parameters like it currently does maybe use def
TypeError: fexpr__12320.call is not a function
at line
(let my-pictures #js {:view (fn [] (
Seems I'm calling the function incorrectlyfixed was minor syntax problems
Hello, I have a dropdown with search input. I am using re-frame. When the search input is in focus, the dropdown shows. When the input loses focus, the dropdown hides. When I click on the dropdown items, the item is supposed to be selected and the dropdown should hide. However, the onblur of the input element “hijacks” the onclick event of the dropdown item. I.e, the latter, and thus the item selection, never happens. How can I fix this? Thanks!
Impossible to tell without having the code or the documentation for that dropdown component.
As a kind of hand-wavy response - don't hide the dropdown on blur immediately, give the other event a chance to be handled.
I thought the code would be long to post here. But here goes the clunky code.
defn geo-zone-selector []
(let [state (r/atom {})] ;; you can include state
(r/create-class
{:component-did-mount
(fn []
(reset! state (assoc @state :drop-down-visible false)))
;; ... other methods go here
;; name your component for inclusion in error messages
:display-name "complex-component"
;; note the keyword for this method
:reagent-render
(fn []
(let [geozones @(rf/subscribe [:geozones])
country (:country geozones)
gettext (fn [e] (-> e .-target .-value)),
getdatavalue (fn [e] (-> e .-target .-dataset .-value)),
getdatafname (fn [e] (-> e .-target .-dataset .-fname)),
getlinktext (fn [e] (-> e .-target .-text)),
spaces (fn [n] (str (apply str (repeat n "\u00A0")))),
change-geozone-input (fn [e] (reset! state {assoc state :geozone-input-value (gettext e)}))
select-geozone (fn [e] (reset! state {:drop-down-visible false
:geozone-input-value (string/trim (getlinktext e))
:selected-geozone {:name (string/trim (getlinktext e))
:code (getdatavalue e)}}))]
[:div.field
[:label.label "Geographic Zone"]
[:div.control
[:div {:class "dropdown is-active"}
[:div {:class "dropdown-trigger"}
[:div {:class "field"}
[:p {:class "control is-expanded has-icons-right"}
;; on focus lost, alert
;; on focus, show dropdown
[:input#geo-zone {:class "input",
:type "search",
:placeholder "Geographic Zone"
:on-focus #(reset! state (assoc @state :drop-down-visible true))
;; :on-blur #(reset! state (assoc @state :drop-down-visible false))
:on-hange change-geozone-input
:value (:geozone-input-value @state)}]
[:span {:class "icon is-small is-right"}
[:i {:class "fas fa-search"}]]]]]
[:div {:class "dropdown-menu", :id "dropdown-menu", :role "menu" :style
{:display (if (:drop-down-visible @state) "block" "none")}}
[:div.dropdown-content {:style {:max-height "250px", :overflow-y "scroll"}}
[:div
[:a {:class "dropdown-item level-1-dropdown" :on-click select-geozone :data-fname (:name country) :data-value (:code country)} (str (spaces 0) (:name country))]
(for [p (:provinces country)]
[:div
[:a {:class "dropdown-item level-1-dropdown" :on-click select-geozone :data-fname (:name p) :data-value (:code p)} (str (spaces 5) (:name p))]
(for [sgz (:districts p)]
[:a {:class "dropdown-item" :on-click select-geozone :data-fname (:name sgz) :data-value (:code sgz)} (str (spaces 10) (:name sgz))])])]]]]]]))}))
Well, my hand-wavy response seems like it's your best bet - just wrap that :on-blur
in a js/requestAnimationFrame
, that should work.
An arguably better approach that would also allow having focus within a dropdown is closing the dropdown only when focus leaves the whole component.
Interesting! I’m leaning towards the second solution. I’ll try them both. Thanks a lot!
It worked with the delay. For some reason, the on-blur is not propagating down to the elements. I’m sure it’s some rookie mistake somewhere. Thanks a lot!
I'm trying to represent the following javascript object in clojurescript
m.route(document.body, "/home", {
"/home": Home,
})
Here is my attempt but it returns a map literal error
(def router[] (m/route (. js/document -body) "/home" #js { ("/home" home-page) }))
The map literal starting with ("/home" home-page) on line 32 column 15 contains 1 form(s). Map literals must contain an even number of forms.
Changing the router to (def router (m/route (. js/document -body) "/" #js {
("/home" home-page)
("/pictures" my-pictures)
}))
returns JavaScript literal keys must be strings or unqualified keywords
(def router-default (
"/" #js {
("/home" home-page)
("/pictures" my-pictures)
}))
(defn route[router] (m/route (. js/document -body) router))
(defn render-content []
(println "test rendering")
(println my-pictures)
(println(. js/document -body))
(route router-default ))
same error of JavaScript literal keys must be strings or unqualified keywords,
removing #js from the map allows the page to render and returns the following console error fexpr__12363.call is not a function
at the object router-default
I think maybe I'm not supposed to have (def router-default ( "/" but rather (def router-default "/" (?
Fixing the extra ()s from function defns and key syntax of {} not {()} fixed all errors but still not rendering components, troubleshooting now
What to use for emacs?
clojure-mode with font-lock?
I think that's just for syntax highlighting not linting
I'll try flycheck-clj-kondo
ended up just using (m/route (. js/document -body) "/" #js {"/" home-page "/pictures" my-pictures})) which just works
any way to extract out "/" #js {"/" home-page "pictures" my-pictures} into an object default-router? Tried a few times and failed, not being recognized correctly as an object
You really need to start properly formatting your code here.
The way you write it right now makes no sense - you wrote 2 values, one is a string "/"
and the other is a JS literal, #js {...}
. You can't assign them both to a single var, if that's what you want.
The closest alternative is to either extract them into their own respective vars or to wrap them in a vector, store it in some var, and use it with that m/route
by using apply
.
Idk what your first paragraph is trying to communicate but the last clause was what I was looking for
If you would explain what you mean by proper formatting it could be helpful to me
And there's more to it than just that button in the WYSIWYG Slack message editor. (Oh, now it has a second button - well, that covers 90% then.)
I'll check if I can find any tutorials on how to format code on slack, I agree with you that the formatting I have been using for code blocks has made me uncomfortable. I'm new to using slack
There are 2 buttons - one for in-line code, the other is for multiline code blocks. You can do the same with just the backtick - inline singular for the former, on their own line around the code block and triple for the latter. The rest 10% is code attachments - they also support syntax highlighting and are collapsible.
I'll try out code attachments, I was annoyed that I didn't have any syntax highlighting
My webapp project is getting bigger. I'm wanting to add more .cljs files than just app.cljs. I'm confused about several things. Firstly, what the recommended practice is for using multiple files (e.g., when one ought to create a new file instead of using the existing one). Secondly, how it is possible to work within an existing namespace in a separate file -- IIRC, ns http://myproject.frontend.app is expecting that it is used with the myproject/frontend/app.cljs path). Thirdly, when one should create a new namespace. E.g., I have http://myproject.frontend.app as my namespace for app.cljs. My assumption is that I should probably have more specific namespaces than this, but as I am a noob I do not know what the recommended practice is
1) whatever makes sense to you. some people group by "components", some by "type", some by "topic". it really is up to you
3) http://myproject.frontend.app is fine. some people use .core
, some .app
, some .main
. whatever makes sense to you