Fork me on GitHub
#fulcro
<
2020-02-02
>
otwieracz14:02:16

Is there anything wrong with my setup, or recomplilation of defmutation (server side) does not have immediate effect?

otwieracz14:02:06

I have to also regenerate handler and parser

mdhaney17:02:37

@slawek098 you probably want some kind of “reloaded” workflow. Look at the Fulcro template for a straightforward example of how to set this up with mount (although you can also use component or some variant if that’s your preference). Using this workflow, when I make a change I first reload the namespace (to make sure it compiles) then restart the system, by running (restart) at the REPL if you’re using the same setup as the Fulcro template. Also note that in Cursive or Emacs (and probably other editors) you can bind the reload command to a keyboard shortcut, so it’s really quick to do this as part of your normal development workflow.

otwieracz17:02:38

@mdhaney I am using component, so (reset) fixes everything - but I am surprised that redefinition of function in runtime does not resolve the issue.

mdhaney17:02:01

Yeah, I think there are a couple things going on there. I remember reading something about Ring and how handlers wouldn’t pick up changes without special steps being taken, and also something about the way Clojure deals with multimethods. TBH, I’ve been using the reloaded pattern so long, I’ve forgotten the details of some of the problems it was trying to solve. ☺️

Jakub Holý (HolyJak)18:02:46

A problem is if you pass a fn by value (the default) - changing the original fn's code then of course has no effect, that's why you typically give #'my-handler to ring. Mulrimethods, protocols etc are troublesome.

geraldodev20:02:32

which reactjs widgets do you use with fulcro, folks ?

otwieracz20:02:58

@mdhaney yeah, but it’s frustrating having to reload every change in source code.

pithyless20:02:21

1. Preferably you map the (reset) to a keybinding in your editor. 2. When I was still using boot, it had a watch filesystem task, and it was easy to run reset from there. 3. You could always e.g. add a ring middleware, so in dev-mode each new HTTP request refreshes your reloadable code

pithyless20:02:18

I've found that with bigger component systems (and access to current state in the repl), I don't actually like it reseting with every file save, so I use (1) - in emacs via .dir-locals.el

otwieracz21:02:30

Actually, the problem I have with (reset) is that I use in-memory datomic db.

otwieracz21:02:41

So every (reset) all the data is gone.

otwieracz21:02:05

wrap-reload also does not seem to work..

pithyless21:02:31

ah, ok; well if it's just a question of defmutation, if you avoid caching your mutations/resolvers within a var (i.e. use defn or #'reference) and create new pathom parser with each request, that should work without (reset)

otwieracz21:02:38

I am not able to make it work.

otwieracz21:02:45

Maybe you can see something inherently wrong?

otwieracz21:02:56

The only way that is working is to enable wrap-reload and save file.

otwieracz21:02:08

But I don't understand why I cant modify function at the runtime..

currentoor22:02:04

you want to be able to update a mutation’s body and eval it and have your system use that new version, correct?

otwieracz22:02:23

But now it stopped working, too..

pithyless22:02:58

if you re-eval the add-connector it's not going to be refreshed in the parser, because the var is cached

currentoor22:02:03

if that’s what you want, you can make a wrapper macro for defmutation, make it output a defn with a stable name and invoke that internal function in the mutation body

currentoor22:02:36

that’s what we’ve done in our project

pithyless22:02:19

@U09FEH8GN wouldn't it be enough to reference it via #'add-connector ?

currentoor22:02:36

but we (@U0CKQ19AQ and I) also strongly recommend test driven development on the server, rather than manual trial-and-error driven development

currentoor22:02:31

@pithyless i’m not sure what you mean

otwieracz22:02:52

(def mutations [#'add-connector]) seems to break things

otwieracz22:02:40

"class clojure.lang.ExceptionInfo: Mutation not found - {:mutation wires.mutations/add-connector}"

otwieracz22:02:17

OK, seems like I've got it

otwieracz22:02:35

Thanks for your help!

otwieracz22:02:54

(hope it will keep working :))

Jakub Holý (HolyJak)18:02:25

@slawek098 doesn't the reloaded workflow have any way to keep some state (your Datomic) across reloads?

tony.kay19:02:21

you can indicate a ns isn’t to be reloaded

tony.kay19:02:27

with tools-ns

tony.kay19:02:35

I think you put metadata on the ns name?

tony.kay19:02:03

or you could make a source dir that has your db in it, and the elide that dir from the call to set-refresh-dirs

thosmos08:02:33

I reload the defmutation namespace and the pathom parser namespace (I don’t need to reload the whole app). I use mount for state management and it automatically reloads the pathom state component when the file is recompiled.

currentoor22:02:24

we also have some authorization/permission stuff mixed in there

currentoor22:02:18

that NS is used by JVM and nodeJS envs

currentoor22:02:50

the JVM one has the internal function trick so you can re-eval a mutation definition and have it take affect immediately