Fork me on GitHub
#shadow-cljs
<
2023-01-28
>
Clojuri0an14:01:54

(def root (. js/document -getElementById "root"))

Clojuri0an14:01:16

TypeError: fexpr__12271 is undefined

thheller14:01:17

context? version? build config? repl?

Clojuri0an14:01:01

not relevant

Clojuri0an14:01:04

but figured out issue

Clojuri0an14:01:13

wrong syntax should have been (def root-div (.getElementById js/document "root"))

Clojuri0an14:01:09

how to pass multiple parameters

Clojuri0an14:01:15

(.render mithril/m root-div "hi")

Clojuri0an14:01:47

original is

m.render(root-div, "Hello world")

thheller14:01:58

that would be correct

thheller14:01:07

assuming m is equal to mithril/m

thheller14:01:13

looks a bit suspicious

Clojuri0an14:01:41

that's mistaken should not have both

Clojuri0an14:01:54

m is just mithril should be mithril/render

Clojuri0an14:01:40

got it running

Clojuri0an14:01:46

mithril with clojurescript is kino

Clojuri0an15:01:28

How to call m("h1", "header")?

Clojuri0an15:01:41

m("h1" "header") doesn't seem to work

thheller15:01:53

(m "h1" "header")

Clojuri0an15:01:30

(m/render (.body js/document) (m "h1" "my epic win") (m "h2" "test") (m "button" "an epic button")))

Clojuri0an15:01:57

whycome TypeError: document.body is not a function

Clojuri0an15:01:55

I understand conceptually that I'm calling function instead of getting object but idk how to get object

Clojuri0an15:01:34

I don't think aget is what supposed to use

Clojuri0an15:01:30

(. js/document -body) return nil

Clojuri0an15:01:52

DOM element being rendered to does not exist.

Clojuri0an16:01:08

figured it out I think desu

Clojuri0an16:01:10

one moment plz

Clojuri0an16:01:23

Writing a hook(?) works DOM needs to load first Not sure if this is a bloated solution?

(ns 
  (:require [mithril :as m]))



(defn render-content []
  (println "test rendering")
  (println(. js/document -body))
  (m/render (. js/document -body)
            (m "h1" "my epic header")))


(defn init []
  ;; tests
  (println "hello world")
  ;; renders
  (.addEventListener js/document "DOMContentLoaded" render-content))

Clojuri0an16:01:34

How to represent something of the form

m("main", [
    m("h1", {class: "title"}, "My first app"),
    m("button", "A button"),
])
(array []?)

Clojuri0an16:01:55

hmm something of the form

(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"))))
works but idk why

Clojuri0an16:01:40

(m "h1" #js {:class "test"} "my epic header") and #js needed to communicate its json object and not a map (just in case this helps anyone ^^