hoplon

The :hoplon: ClojureScript Web Framework - http://hoplon.io/
2018-07-15T04:28:24.000028Z

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?

vigilancetech 2018-07-15T18:36:31.000072Z

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.

2018-07-15T19:09:41.000061Z

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

2018-07-15T19:10:15.000026Z

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

2018-07-15T19:10:39.000043Z

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

2018-07-15T19:10:59.000063Z

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

vigilancetech 2018-07-15T19:11:53.000024Z

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

2018-07-15T19:11:59.000060Z

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

2018-07-15T19:12:34.000010Z

i think there are differences to each of these

2018-07-15T19:13:25.000023Z

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

2018-07-15T19:15:47.000027Z

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

vigilancetech 2018-07-15T19:16:12.000009Z

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.

2018-07-15T19:16:20.000080Z

ohhhhh

2018-07-15T19:16:25.000058Z

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

2018-07-15T19:17:29.000013Z

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

vigilancetech 2018-07-15T19:17:55.000014Z

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

2018-07-15T19:18:10.000023Z

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

vigilancetech 2018-07-15T19:18:12.000047Z

so I'd have to do all that dissecting manually

2018-07-15T19:18:17.000033Z

the latter being no macros

vigilancetech 2018-07-15T19:22:58.000023Z

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

2018-07-15T19:24:42.000064Z

can you post the code here?

vigilancetech 2018-07-15T19:25:14.000030Z

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

vigilancetech 2018-07-15T19:26:14.000043Z

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

vigilancetech 2018-07-15T19:28:08.000007Z

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

vigilancetech 2018-07-15T19:29:29.000002Z

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)

2018-07-15T19:31:13.000065Z

hmmm

vigilancetech 2018-07-15T19:32:08.000021Z

actually I edited that to be a bit more complete

vigilancetech 2018-07-15T19:34:31.000022Z

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

2018-07-15T19:35:45.000015Z

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

vigilancetech 2018-07-15T19:36:45.000002Z

like the thing the do does just before returning true?

2018-07-15T19:36:54.000028Z

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

2018-07-15T19:37:04.000045Z

yup

vigilancetech 2018-07-15T19:37:08.000022Z

k

vigilancetech 2018-07-15T19:37:47.000031Z

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

2018-07-15T19:48:05.000069Z

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

vigilancetech 2018-07-15T19:48:24.000041Z

sorry, fighting with another error here for a few mins

2018-07-15T19:48:27.000064Z

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

2018-07-15T19:48:48.000040Z

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

vigilancetech 2018-07-15T19:48:49.000016Z

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

2018-07-15T19:51:56.000001Z

i vaguely remember running into oddities with checkbox stuff

vigilancetech 2018-07-15T20:03:22.000056Z

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

vigilancetech 2018-07-15T20:05:52.000045Z

preventdefault stops the box from unchecking at all

vigilancetech 2018-07-15T20:15:50.000057Z

:change works with .preventDefault but the javelin problem remains

2018-07-15T22:53:01.000029Z

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

2018-07-15T22:54:51.000044Z

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

vigilancetech 2018-07-15T23:56:32.000081Z

@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

vigilancetech 2018-07-15T23:57:18.000070Z

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