mount

jrychter 2016-01-22T10:54:51.000483Z

@tolitius: I converted all my server-side code to mount and it works well. I'm quite happy with the results!

🦜 2
jrychter 2016-01-22T10:56:13.000484Z

But I also have a question. I would like to modify the state from elsewhere (other functions, not just lifecycle functions). Is that… legal? :simple_smile:

jrychter 2016-01-22T10:56:47.000485Z

An example is: start defines a pub/sub structure, and later on I start subscribing channels to it. I need to keep track of subscribed channels so that on stop I can unsubscribe them properly.

jrychter 2016-01-22T10:57:26.000486Z

Or should I just keep those in a separate atom?

dm3 2016-01-22T11:00:59.000487Z

you can have a ns to track the subscriptions, e.g. subscriptions/subscribe!

jrychter 2016-01-22T11:01:40.000489Z

Then again, perhaps I don't have to do this at all… core.async docs aren't that clear on this, but if you close the source of the pub, pub should close as well, which should also close all subscribed channels.

jrychter 2016-01-22T11:02:16.000490Z

I guess I could also keep that additional state in an atom inside the defstate state

jrychter 2016-01-22T12:11:06.000491Z

Well, for ClojureScript the picture isn't so rosy. In one of my namespaces, modifying the file causes the start function to be called twice. Not good.

jrychter 2016-01-22T12:14:38.000492Z

Also, the order seems wrong: ns1 :require's ns2, but ns1's start is called first, then ns2's start. Twice. I think I'll stick to manual state management here for now…

jrychter 2016-01-22T12:16:09.000493Z

Could mount be somehow confused because it is only required in two namespaces?

jrychter 2016-01-22T12:30:06.000494Z

What's worse, this problem seems to appear and disappear without any regularity that I can notice.

dm3 2016-01-22T12:49:03.000495Z

does this happen during the development?

jrychter 2016-01-22T12:53:32.000496Z

Yes, with figwheel. But I checked all combinations of cleaning/rebuilding.

jrychter 2016-01-22T12:54:01.000497Z

It seems to have goten rare (or nonexisting) once I converted the entire app to mount, but I'm still looking carefully.

jrychter 2016-01-22T13:45:47.000498Z

Ok, so the problem definitely exists. I have a dispatcher namespace, that is required by pretty much everything else. Changing that file results in start being called twice, also after browser reload. I have to clean JavaScript and restart the whole figwheel environment for things to work again. What's curious, it is only this namespace that seems to be so affected.

tolitius 2016-01-22T15:06:14.000499Z

@jrychter: dispatcher is on cljs side, right?

tolitius 2016-01-22T15:18:55.000500Z

also if you are not using it, can you try 0.1.9-SNAPSHOT

tolitius 2016-01-22T15:23:53.000501Z

I find lein cljsbuild to behave oddly at times (environmental), hence I am using boot for most of the projects, it always starts clean. I know it would be a lot to change, but I definitely recommend giving it a try.

tolitius 2016-01-22T15:26:54.000502Z

> "the order seems wrong: ns1 :require's ns2, but ns1's start is called first, then ns2's start" mount simply obeys the compiler. it could theoretically happen when moving states from one place to another.. without reloading

jrychter 2016-01-22T15:27:45.000503Z

So, in order: everything I described in on cljs side. Clojure side works great. I am not using 0.1.9-SNAPSHOT, will try right away.

jrychter 2016-01-22T15:28:43.000504Z

As for boot, been there, done that — we tried boot in a project in our company, it has its own set of problems. Nothing is perfect.

jrychter 2016-01-22T15:33:37.000505Z

What is curious is that after changing and saving dispatcher.cljs, stop gets called (once) and start gets called (once). So everything looks good. But if I reload the app, start will get called twice. It will get called twice from then on, until I clean the JavaScript files.

jrychter 2016-01-22T15:34:13.000506Z

Trying 0.1.9-SNAPSHOT now.

jrychter 2016-01-22T15:38:08.000507Z

I get the same thing with 0.1.9-SNAPSHOT. I guess I must not change the dispatcher file, then. I will implement a one-shot atom checking if start was run twice.

tolitius 2016-01-22T15:39:52.000508Z

I wonder whether mount detects that something with a state was reloaded before it was stopped and restarts it, and then you call (mount/start) in the app which result in two start calls. do you see messages about ns recompile in the console:

jrychter 2016-01-22T15:50:53.000510Z

Yes. And everything works as expected, except for the dispatcher namespace. Triggering recompilation for that one does everything as expected (it stops and then starts everything that depends on it). But after a reload the start method gets called twice. Every time I start the app.

jrychter 2016-01-22T15:51:37.000511Z

My current fix is to rm -rf resources/public/static/js after this happens. This triggers a full recompilation next time I change something, and fixes the double-start problem.

tolitius 2016-01-22T16:01:27.000512Z

But after a reload: you mean after figwheel pushes changes to the browser you see :start being called twice?

tolitius 2016-01-22T16:05:08.000514Z

i.e. or when you reload the page in the browser..

jrychter 2016-01-22T16:15:45.000515Z

After figwheel pushes changes to the browser things are fine. But after a browser reload (Command-R in my case) start gets called twice.

tolitius 2016-01-22T16:21:58.000516Z

need to think more about it... would you mind to create an issue? when I have time I'd like to check whether it is caused be environment or this is truly a defect

jrychter 2016-01-22T16:22:59.000517Z

Of course. I am still trying to narrow it down.

tolitius 2016-01-22T16:27:39.000518Z

great, thanks!

jrychter 2016-01-22T16:28:10.000519Z

What I find worrying is something I noticed right now:

jrychter 2016-01-22T16:29:13.000521Z

The little number (2) on the left. I added a logging message at the toplevel of my dispatcher namespace, and it also gets a (2). Why would things happen twice? Checked this both with figwheel and with a production cljsbuild with :advanced optimization. Same result.

tolitius 2016-01-22T16:36:14.000522Z

> with a production cljsbuild with :advanced optimization first time you open a page everything loads normally, but after you reload the page :start gets called twice?

jrychter 2016-01-22T21:08:15.000524Z

No, the last message was only about duplicated log message that I added in my namespace. I expected the namespace to be loaded just once, and to see one log message. Instead, I see two. mount doesn't seem to produce any logging when compiled with :advanced.