Fork me on GitHub
#hoplon
<
2018-07-15
>
anisk04:07:24

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?

vigilancetech18:07:31

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.

jjttjj19:07:41

@vigilancetech can you post the code example that's not working?

jjttjj19:07:15

there's with-dom and with-init! macros in hoplon.core

jjttjj19:07:39

the former "Evaluates the body after [given] elem has been inserted into the DOM.""

jjttjj19:07:59

second with-init! "Evaluates the body after Hoplon has completed constructing the page."

vigilancetech19:07:53

@jjttjj oh yeah, I think I recall seeing that in the demos somewhere

jjttjj19:07:59

(.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-clojurescript

jjttjj19:07:34

i think there are differences to each of these

jjttjj19:07:25

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

jjttjj19:07:47

(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))

vigilancetech19:07:12

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.

anisk19:07:25

Hey... Anyone know where the haml task went?

jjttjj19:07:29

fwiw it's possible to use javelin formula directly without macros

vigilancetech19:07:55

yeah, for some reason my macroexpand isn't working either 😕

jjttjj19:07:10

ie (cell= (+ a b)) = ((formula +) a b)

vigilancetech19:07:12

so I'd have to do all that dissecting manually

jjttjj19:07:17

the latter being no macros

vigilancetech19:07:58

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

jjttjj19:07:42

can you post the code here?

vigilancetech19:07:14

eh, let me see if I can get enough of it together to be informative

vigilancetech19:07:14

I was trying to duplicate the 2nd working example here: https://clojurians-log.clojureverse.org/hoplon/2017-03-11.html

vigilancetech19:07:08

(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" )

vigilancetech19:07:29

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)

vigilancetech19:07:08

actually I edited that to be a bit more complete

vigilancetech19:07:31

the reference "data" is getting updated in real time by another part of the program

jjttjj19:07:45

this is kinda a long shot but what about putting a (.preventDefault %) in the :click handler just above the true return value

vigilancetech19:07:45

like the thing the do does just before returning true?

jjttjj19:07:54

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

vigilancetech19:07:47

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

jjttjj19:07:05

another quick "throw stuff at the wall" thing to try is maybe try :change instead of :click for the handler

vigilancetech19:07:24

sorry, fighting with another error here for a few mins

jjttjj19:07:27

that seems to be a bit more appropriate of you're looking to handle the click

jjttjj19:07:48

no worries i was messing with it a bit but have to run out in a min

vigilancetech19:07:49

oh yeah, I played with that yesterday, but just to do a notify to see when it went off

jjttjj19:07:56

i vaguely remember running into oddities with checkbox stuff

vigilancetech20:07:22

it seems like it changes the checkbox checked state BEFORE running the click callback which is somewhat confusing

vigilancetech20:07:52

preventdefault stops the box from unchecking at all

vigilancetech20:07:50

:change works with .preventDefault but the javelin problem remains

chromalchemy22:07:01

@vigilancetech f-e is already a formula cell. Do you need to wrap it in another for :checked?

chromalchemy22:07:51

Also maybe define the specter path fn n-device-records using (sp/path)

vigilancetech23:07:32

@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

vigilancetech23:07:18

yes, I need to bone up on specter a lot. Thanks, I'll check it out.