Hey... So I'm getting this strange error about > template already refers to: #'boot.core/template in namespace: adzerk.boot-reload Anyone know what's going on?
how do I get the document.ready or window.onload callback to work (to run my code after the web page has loaded)? Either that or how do I elegantly get the address of a DOM element so I can manipulate it directly? I'm having a problem with some checkboxes not javelin updating based on changed data being extracted with specter after the checkbox has been manually manipulated (strangely until I either restart the boot process and browser, or make a change to the hl source file and recompile then boot's reload puts everything back right; the browser reload button -- even WITH shift -- doesn't help). I could .getElementById every time something changes but it seems somewhat wasteful.
@vigilancetech can you post the code example that's not working?
there's with-dom
and with-init!
macros in hoplon.core
the former "Evaluates the body after [given] elem has been inserted into the DOM.""
second with-init!
"Evaluates the body after Hoplon has completed constructing the page."
@jjttjj oh yeah, I think I recall seeing that in the demos somewhere
(.addEventListener
js/window
"DOMContentLoaded"
(fn [] (.log js/console "DOMContentLoaded callback")))
should work also according to https://stackoverflow.com/questions/35706538/equivalent-of-document-readyfunction-in-clojurescripti think there are differences to each of these
as for getting a dom element to manipulate it, usually that's the wrong way to think in hoplon. you don't need to get an elem by address because you usually work with the elements directly
(def my-elem (h/div "hello world"))
(h/html
(h/head)
(h/body
(h/button :click #(h/set-attributes! my-elem :id (str "new-id-" (rand-int 10))))
my-elem))
yes, I realize the situation is effed up, but its something to do with specter and javelin macros not playing well together but I'm on a deadline right now.
ohhhhh
Hey... Anyone know where the haml task went?
fwiw it's possible to use javelin formula
directly without macros
yeah, for some reason my macroexpand isn't working either 😕
ie (cell= (+ a b))
= ((formula +) a b)
so I'd have to do all that dissecting manually
the latter being no macros
yeah, its kind of a complicated formula. I might be able to load it up in a clojure, rather than clojurescript, repl and macroexpand it to see what it produces. The clojurescript one just gives me back what I put in
can you post the code here?
eh, let me see if I can get enough of it together to be informative
I was trying to duplicate the 2nd working example here: https://clojurians-log.clojureverse.org/hoplon/2017-03-11.html
(defn n-device-records [type] [:lights sp/ALL #(= (:type %) type)])
(defn effects [d type] (sp/select [(n-device-records type) :effect] d))
(defn fan-effects [d] (effects d :fan))
(defc= f-e (not (every? #(= "none" %) (fan-effects data))))
then in (window...
(input :id "FANS" :value "FANS" :type "checkbox"
:checked (cell= f-e)
:click #(do (if (checked? "FANS") (checkbox-checked :fan)
(checkbox-unchecked :fan))
true) "FANS" )
The checkbox is supposed to automatically track the state of the effect, but when it gets checked off manually (which disables the device group) but then one device in the group gets enabled, the checkbox no longer tracks (e.g. the javelin cell doesn't appear to be running)
hmmm
actually I edited that to be a bit more complete
the reference "data" is getting updated in real time by another part of the program
this is kinda a long shot but what about putting a (.preventDefault %) in the :click handler just above the true
return value
like the thing the do does just before returning true?
my initial thought is that maybe the default dom action is to set the value of the checkbox to "true" on a click in place of the cell that was there
yup
k
I can go in with JS interop and force the checkbox back on and it works, but not otherwise except for a total restart or a boot reload after an edit/compile
another quick "throw stuff at the wall" thing to try is maybe try :change
instead of :click
for the handler
sorry, fighting with another error here for a few mins
that seems to be a bit more appropriate of you're looking to handle the click
no worries i was messing with it a bit but have to run out in a min
oh yeah, I played with that yesterday, but just to do a notify to see when it went off
i vaguely remember running into oddities with checkbox stuff
it seems like it changes the checkbox checked state BEFORE running the click callback which is somewhat confusing
preventdefault stops the box from unchecking at all
:change works with .preventDefault but the javelin problem remains
@vigilancetech f-e
is already a formula cell. Do you need to wrap it in another for :checked
?
Also maybe define the specter path fn n-device-records using (sp/path)
@chromalchemy well, I was following the 2nd working example in that page I linked. Its so brittle I haven't tried more possibilities. Obviously that wasn't a complete solution cuz I tried to be pretty true to its form
yes, I need to bone up on specter a lot. Thanks, I'll check it out.