This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-31
Channels
- # announcements (2)
- # babashka (145)
- # beginners (260)
- # calva (17)
- # chlorine-clover (7)
- # clj-kondo (9)
- # cljsrn (1)
- # clojure (88)
- # clojure-dev (65)
- # clojure-europe (31)
- # clojure-france (4)
- # clojure-nl (4)
- # clojure-uk (61)
- # clojuredesign-podcast (1)
- # clojurescript (31)
- # code-reviews (1)
- # cursive (32)
- # data-science (2)
- # datascript (9)
- # datomic (39)
- # docker (3)
- # events (1)
- # figwheel (95)
- # figwheel-main (4)
- # fulcro (17)
- # kaocha (2)
- # keechma (1)
- # malli (1)
- # meander (35)
- # nrepl (4)
- # off-topic (1)
- # pathom (8)
- # re-frame (4)
- # reagent (8)
- # reitit (3)
- # releases (1)
- # remote-jobs (2)
- # shadow-cljs (182)
- # sql (30)
- # tools-deps (89)
- # xtdb (31)
I'm working on a page with some elements that have an :on-click handler, something like:
[:tr {:class "stripe row-normal"
`:style {:font-size "10px"}`
`:id (str "row-" content-id)`
`:key (get record-item :DocumentId)`
`:on-click #(select-row-event %)}`
This is working fine but I also want to handle the onmouseover
and onmouseout
events and I can't figure out how to do this. I'm sure I'm missing something obvious but after trying every combination I can think of (:onmouseover, :on-mouseover, :on-mouse-over, etc.) I can't seem to get the event handler to fire.
hey all, cljs question for you... I'm trying to work with BigInt, and finding that I can compare bigints no problem:
cljs.user> (= (js/BigInt 0) (js/BigInt 0))
;; => true
but then if I make a protocol...
(defprotocol Cake
(is-zero? [this]))
(extend-protocol Cake
js/BigInt
(is-zero? [x] (= x (js/BigInt 0))))
sicmutils.value> (is-zero? (js/BigInt 0))
;; => false
I can't get this to return true
ah, boom, got it!
(let [big-zero (js/BigInt 0)]
(extend-protocol Cake
js/BigInt
(is-zero? [x] (= (.valueOf x) big-zero))))
you need (.valueOf x)
inside the protocol, apparently
I don't think bigint has any instance methods https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
hmm, reading on that page, a BigInt should compare loosely to a number with the same value. 0n == 0
.
(extend-type number
IEquiv
(-equiv [x o] (identical? x o)))
this is a bit too harsh there then@dpsutton it does not, unfortunately
@dpsutton you'd prefer that over (= (.valueOf x) (js/BigInt 0))
?
which seems to work, but is maybe more mysterious?
yup, that's almost certainly better, then
(nullity? [x] (js* "~{} == ~{}" big-zero x))
(unity? [x] (js* "~{} == ~{}" big-one x))
okay, here we go!
I'm caching big-one
and big-zero
maybe too defensively...
thanks for the tips
I think "bubbling" is a good alternative to callbacks. here's some pseudo code for how it would look like with bubbling:
(ns my.generic-components.date)
(defn datepicker [& {:keys [current-date]} ]
(date-layout
(for [date (date-range current-data)]
(on
:mouse-down
(fn [_]
[[::select-date date]])))))
(ns my.specific.ui.order-form )
(defn delivery-date-field [& {:keys [order-form]}]
(vertical-layout
(ui/label "Please choose a delivery date:")
(ui/on
::select-date
(fn [child-handler d]
(when (time/after?
(time/floor d time/day)
today-date)
[:mayapp.orders.events/set-order-delivery-date cart-id new-delivery-date]))
(datepicker :current-date (:myapp.order-form/date order-form)))))
In this example, the ::select-date
event bubbles up and can be caught by any parent component. the parent component can then transform that into a new event :myapp.orders.event/set-order-delivery-date
@U7RJTCH6J sometimes you want to customize other things than events, e.g sub-parts of the rendering
@U4YGF4NGM, that would be neat
i've been experimenting with bubbling and liking it, but my implementation circumvents the usual event handling rather than leveraging it.
https://github.com/active-group/reacl/blob/master/doc/intro.md 🙂 here's the lib I was thinking of