Fork me on GitHub
#clojurescript
<
2019-07-28
>
Danny Almeida07:07:50

I'm trying a sample code in fulcro 3 development docs ... (defonce app (app/fulcro-app)) (def example-person (atom {:person/name "Wilson" :person/age 46})) (defsc Person [this {:person/keys [name age]}] (dom/div (dom/div (dom/label "Name: " name)) (dom/div (dom/label "Age: " age))) ) (def ui-person (comp/factory Person)) (defsc Root [this props] (dom/div (ui-person @example-person)))

Danny Almeida07:07:51

When i change example-person ..it's rendered immediately However, if I change it to defonce, changing example-person in REPL e.g (reset! example-person {:person/name "Abc" :person/age 25}) has no effect.

Danny Almeida07:07:25

I have to do (app/mount! app Root "app") to force a re-render

Danny Almeida07:07:49

Can someone please explain why this is so ?

padraic11:07:43

Could someone explain to me how to create macros in clojurescript. I've been trying to institute <? macro by hand but have gotten repeating errors. As far as I am aware, it is a compile vs runtime thing and requires that the macro must be defined at compile time and therefore must be in a seperated clj/cljc file? I have tried this but have not gotten much success

thheller11:07:29

@sirromdev what have you tried? you basically just create a .clj and a .cljs file of the same name and then have the CLJS version (ns foo.bar (:require-macros [foo.bar]))

padraic11:07:56

I have tried just as you said, well with a .cljc instead of .clj

padraic11:07:01

(ns eth.macros)

(defn throw-err [e]
 (when (instance? #?(:clj Throwable :cljs js/Error) e) (throw e))
  e)

(defmacro <?
  [ch]
  `(throw-err (cljs.core.async/<! ~ch)))
(ns eth.macros)

padraic11:07:48

There is a corresponding cljs file of the same name requiring the macros just the same

padraic11:07:04

The issue that occurs is that the throw-err is not defined

padraic11:07:31

Use of undeclared Var eth.macros/throw-err

thheller11:07:05

and you do have the :require-macros in the CLJS variant of eth.macros?

padraic11:07:35

(ns eth.macros
  (:require-macros [eth.macros]))

padraic11:07:44

All that is in that file is that

thheller11:07:03

ah you have the throw-err defined in the macros file

thheller11:07:08

that should be in the CLJS variant

padraic11:07:50

That works a treat thanks @thheller (btw shadow is great)

👍 4