This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-19
Channels
- # bangalore-clj (35)
- # beginners (42)
- # boot (89)
- # cider (9)
- # clara (2)
- # cljs-dev (29)
- # cljsjs (3)
- # cljsrn (14)
- # clojars (9)
- # clojure (332)
- # clojure-brasil (1)
- # clojure-dev (5)
- # clojure-italy (4)
- # clojure-russia (36)
- # clojure-spec (38)
- # clojure-uk (65)
- # clojurescript (114)
- # clr (11)
- # community-development (105)
- # core-async (10)
- # cursive (4)
- # datascript (1)
- # datomic (58)
- # defnpodcast (3)
- # emacs (4)
- # hoplon (7)
- # juxt (3)
- # keechma (8)
- # off-topic (7)
- # om (109)
- # om-next (8)
- # onyx (26)
- # pedestal (3)
- # planck (8)
- # re-frame (76)
- # reagent (28)
- # rum (25)
- # spacemacs (2)
- # specter (35)
- # untangled (31)
- # yada (27)
(dispatch-sync [:init])
is indeed effectful. It sets the initial state of the application. Ie. it causes an initial value to be put into the one big atom app-db
I'm not sure of the context here (dunno much about boot yet) but thought I'd chime in on that part
one one hand you need to initialize the application in the main napespace when the application is first loaded
I saw re-frame mentioned and thought "i can help here" but then ran into my lack of boot knowledge.
Oh, I get it
So this is a figwheel-like situation ?
Hot reloads
the solution i proposed was something like this, assuming a function init
that does the initialization
(let [loaded? (atom false)]
(defn on-js-load []
(if @loaded?
(init)
(reset! loaded? true))))
Or the other way might be ... the handler for the event [:init]
could check to if app-db
already has a value and not give a new value if it does
Most of the time you want the app state retained
You want new code loaded but you want the state of the app to be retained
@michael.heuberger can work it as he sees fit. I'll give a code fragment ...
It seems to me you want to make the handler do nothing when it is called the 2nd, 3rd, etc time. It should do a correct initialisation the first time. But every time thereafter, it should be a noop
If that's correct, so something like this ...
(def-event-db
:init
(fn [db _]
(if (= db {}) ;; initially db will be {}
(...... return the initial value to be put in app-db)
db))) ;; <--- don't change anything ... just keep existing state as is
(just going to say that I love both Boot and re-frame, so seeing this discussion about integrating them, before I run into the same challenges, is fantastic)
@michael.heuberger Do you call the init fn from cljs.edn and the namespace top-level?
Don't use :init-fns
and the init function will only be called once
@juhoteperi how will it only be called once when he puts it into the ns toplevel?
once per load
how does this work? like when I change the namespace the function is called again no?
then I'm confused but I'll just accept it for now 😄
but the problem was that init! was called twice per reload
maybe
or twice per initial load
ah ok, then I misunderstood 🙂
so is it possible to have macros in pod with-eval-in
code? like when
, I have a strange problem with symbols and I guess I am not unquoting correctly
@richiardiandrea i ran into strange thing there recently myself
@richiardiandrea https://github.com/adzerk-oss/boot-logservice/commit/c9b5e576cd9d98e613a26815aa53601266ce7fe8
uhm I am trying a couple of things with bt/template
to see what is wrong as we speak, maybe it is just me 😉
in my case i was able to reproduce using backtick directly, i worked around by using .invoke
@alandipert I am exactly working with a boolean named autostart?
can it be the name? 😄
I'm good at hitting buttons lol
lol thanks @martinklepsch I still don't dare merging myself 😄
I was thinking I'd just leave a comment if it looks good to me but didn't make much sense with such change
@alandipert moment of lazyness, is there a way to macroexpand with backtick?
@richiardiandrea there's macroexpand-all in clojure.walk?
ah ok, I thought I needed some particular thing for it to work with backtick...
so basically this works:
boot> (bt/template (do ~@(when '~autostart?
;; Auto-start the system
(require 'dev))))
this does not:
(bt/template (do ~@(when '~autostart?
;; Auto-start the system
(require '~'dev)
(dev/go)))) ;; No such namespace: dev
the latter expands to:
(clojure.core/apply
clojure.core/list
(clojure.core/concat
[(quote do)]
(if
(quote (clojure.core/unquote autostart?))
(do (require (quote dev)) (dev/go)))))
now I see I need to quote it right?
@richiardiandrea you wanna do ((resolve 'dev/go))
oh...lol
thanks guys
the weird thing is that without the when
everything works, but there must be an explanation to that as well
ah ok, yes because the require
did work, the dev/go
didn't (which is in a do in with-eval-in
definitely)
vars are resolved at compile time, and because the require the the dev/go where in the same compilation unit, the require hadn't run when clojure went to compile dev/go, so the compiled couldn't find the var
the compiler treats each thing in a top level do as its own top level form, so each thing in a top level do is its own compilation unit
btw @hiredman welcome to the party, good to have you
mmm, probably the macro force is not strong in myself at the moment, but aren't both the when
and the non-`when` version in a do
?
but that is exactly the above isn't it...I am still a bit confused 😄
I mean
(if
(quote (clojure.core/unquote autostart?))
(do (require (quote dev)) (dev/go))
assuming autostart?
is trueah ok now it starts to make sense
yes true
awesome, crystal clear now
uff, I think thanks to you guys I leveled up 😄