This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-22
Channels
- # aatree (21)
- # announcements (10)
- # avi (1)
- # aws (15)
- # beginners (96)
- # boot (269)
- # braid-chat (92)
- # cider (9)
- # clara (10)
- # cljs-dev (3)
- # cljsjs (14)
- # cljsrn (20)
- # clojure (198)
- # clojure-art (3)
- # clojure-hamburg (2)
- # clojure-ireland (4)
- # clojure-russia (117)
- # clojure-spain (3)
- # clojured (1)
- # clojurescript (253)
- # code-reviews (6)
- # community-development (7)
- # conf-proposals (52)
- # core-async (4)
- # cursive (4)
- # datomic (4)
- # devcards (1)
- # emacs (59)
- # euroclojure (5)
- # funcool (1)
- # hoplon (39)
- # human (1)
- # jobs (4)
- # ldnclj (15)
- # ldnproclodo (1)
- # leiningen (3)
- # mount (37)
- # off-topic (14)
- # om (77)
- # perun (10)
- # proton (12)
- # rdf (1)
- # re-frame (9)
- # reagent (42)
- # ring-swagger (10)
- # yada (50)
@tolitius: I converted all my server-side code to mount and it works well. I'm quite happy with the results!
But I also have a question. I would like to modify the state from elsewhere (other functions, not just lifecycle functions). Is that… legal?
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.
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.
I guess I could also keep that additional state in an atom inside the defstate state
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.
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…
What's worse, this problem seems to appear and disappear without any regularity that I can notice.
It seems to have goten rare (or nonexisting) once I converted the entire app to mount, but I'm still looking carefully.
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.
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.
> "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
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.
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.
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.
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.
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:
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.
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.
But after a reload
: you mean after figwheel pushes changes to the browser you see :start
being called twice?
After figwheel pushes changes to the browser things are fine. But after a browser reload (Command-R in my case) start gets called twice.
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
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.