This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-10
Channels
- # beginners (191)
- # boot (3)
- # cljs-dev (2)
- # clojure (46)
- # clojure-austin (1)
- # clojure-spec (4)
- # clojure-uk (32)
- # clojurescript (10)
- # clojurewerkz (3)
- # cursive (14)
- # datomic (88)
- # defnpodcast (1)
- # editors (2)
- # fulcro (2)
- # hoplon (3)
- # jobs (4)
- # jobs-discuss (1)
- # luminus (5)
- # lumo (6)
- # off-topic (13)
- # random (1)
- # re-frame (50)
- # reagent (245)
- # remote-jobs (1)
- # spacemacs (3)
- # specter (16)
- # uncomplicate (4)
Hi, I am using figwheel from cider, using piggyback. The template is reagent-figwheel. It all worked well, but now, when I autoreload some new code, I get
core.cljs:270 Uncaught Error: No protocol method IDeref.-deref defined for type cljs.core/LazySeq: ({:file "resources/public/js/dev/tool/state.js", :namespace "tool.state", :type :namespace, :loaded-file true} {:type :namespace, :namespace "tool.core", :loaded-file true})
and this list appears in a place where my state atom should be. When I reload the page in the browser, it works again Oo
Any idea what might be causing this?My initial guess is that some of your code is re-deffing the symbol that your state-atom was previously bound to…
Do you have your code on github, @mrchance ?
unfortunately no, it's a work project... I could make a gist with some parts of the setup?
I guess that’d help, but without the entire code base, the error could always be occurring elsewhere 😄
maybe try to reduce your code base until the error doesn’t occur, then re-introduce functionality until it does
Ok, but basically I should check for other code that might redefine the app-state symbol
But how does figwheel related information end up there? That's pretty surprising to me
I think that’s the most obvious answer, yeah
good question
what’s the symbol name?
maybe just try changing the state atom’s symbol name where it’s def
ed or defonce
ed and see if it helps?
that could save you the hunt for the re-def (if it turns out that it doesn’t help)
ah, but of course you’d have to make your change a refactor in order to ensure that references to the state atom are also changed, or else your app will (I’m guessing) stop working entirely
and if you’re using an automated refactor of some kind, it might be that you’ll also be changing the name where in the re-def (if there is one such)
also, do you know the difference between def
and defonce
in this context?
if you’re not using defonce
, you probably should 😄
I've used reagent in several projects already, so I have a pretty good idea about the overall setup, but I've never seen this problem before
ah well… I feel like I’m always hitting corner cases, even though I’ve done several (toy) reagent projects now, as well
that is to say, I feel your pain 🙂
(and one serious project, btw. It’s not all fun and games!)
oh yeah, for sure
I think it’s probably preferable to a lot of other approaches
as someone so eloquently said: "Out of all programming languages, Clojure sucks the least"
what that guy said ☝️
anyhow
curious to hear what you discover about the error
if you can reduce the code so much as to become “anonymous”, with the error still persisting, and copy it to a project that does not include business names or other info, I could check it out and try to run it
I use cider, too
I'll let you know: Preliminary result: renaming the var and also all parameter names didn't help 😞
Also, running the same just via lein figwheel
produces the same error, so that's nice at least 😉
yeah, that’s good 🙂
Main difference from the template is that I made all helper functions take a parameter instead of referring to the global atom
I like my global state to be confined to a narrow space in the dev setup if possible
scrutinizing
and you tried with (defonce global-app-state (make-initial-state))
, too?
when dereffing, on line 36?
(defn current-page [state-ratom]
(let [page-key (:page @state-ratom)]
[(page page-key) state-ratom]))
the second line here, I meanor is it further down, in the component that you’re putting into the vector?
I am not comfortable using defmulti
and defmethod
, btw, so I cannot tell whether you are using them correctly
@mrchance at first glance, the ns declaration just says state
instead of tools.state
. Id try changing it (as well as using defonce
... definitely shouldnt be def) and then running (reload-config)
in your figwheel repl
I’ll try to follow the flow in my REPL
And the error occurs directly in the deref in current page @reefersleep , not further down. A println there also shows that it doesn't receive an atom
@gadfly361 Thanks for the template btw., it's really helpful. Have used it in several projects without problems before
try to trace back and see where the value does come from. I guess, directly from the app state ns. so maybe that doesn’t help you
racking my brain trying to come up with a way to detect the change
not coming up with anything new… still think you should try to reduce the number of references to your state atom until the error stops occurring. And if it does not stop occurring, well, then I guess it’s a tooling problem
yes, might be the most sensible route. I'll let you know if I find anything. Thanks for looking into it
and then you’ll probably want to look at your project.clj
setup, and maybe your .lein/profiles.clj
file
and possibly your cider setup 😄
take a look at this: https://github.com/gadfly361/reagent-figwheel/blob/master/src/leiningen/new/reagent_figwheel/gadfly/src/app/core.cljs#L56-L64
basically, on reload, it isn't getting it, which is why your deref doesnt work ... it is nil
I thought of this, but thought I was wrong!
That reload
was parametrized… and thought to ask you just not to have that param
hm, could I just remove it from the project.clj? It shouldn't be necessary to reload it every time, right?
Also, it feels slightly wrong to have figwheel pass it additional parameters that just magically disappear because of the way js works 🙂
just omit your param?
What's the difference to just :figwheel true
? I am reasonably sure I had apps that didn't call any reload functions
btw @gadfly361 , did you have a good meetup in Copenhagen? Sorry I couldn’t attend
@reefersleep Yeah, it was great! Some very nice people there 🙂 Got to meet your buddy @grav and a few others
neat! haven’t seen him in a while actually, he’s in Canada currently, I think…
What you said.
There’s nothing figwheel-specific about your reload
function
I think!
It’s just your mounting function 🙂
and figwheel takes care of (in some other fashion) replacing your def’ed functions with their new versions
maybe this is my cue to read up on how figwheel works
exactly, I just checked, in my projects before the reagent-figwheel
template I never used the on-jsload
hook.
I think it's just if you have to clean up other state, like say core.async channels or something
can you try replacing with true using figwheel-template, because when i do, i don't get the updates as expected
I am assuming you did, but just to make sure since i am trying the same thing and getting a different result - you killed your figwheel repl and restarted it? not just running (reload-config)?
np 🙂 will we get to see your app sometime?
oh yeah, @gadfly361 is on to something, I always make sure to completely reboot stuff when I’m troubleshooting
to avoid pesky state obscurances
Hm, unlikely, unless you happen to work for the particular large european company I am building it for 😉
and you’re already onto that. great!
I might at some point 😛
currently, I work for the state of Denmark
yes, that's one of my core learnings with cljsbuild and figwheel as well, when in doubt, restart everything 🙂
They already did a Clojure project some time ago, and apparently ran into some problems 😞
If I follow these steps:
lein new reagent-figwheel foobar +routes
cd foobar
;; change :figwheel {:on-jsload "foobar.core/reload"} --> :figwheel true
lein figwheel dev
;; change text in home page
hrm, that's really weird, just stopped everything, did a lein clean
and lein figwheel
to restart it, and it still works
thanks! will be helpful for me to understand the diff between fresh template and your working version (assuming yours no longer has a defmulti)
@mrchance we use Clojure and Clojurescript (and reagent)
it’s why I took the job 😄
it’s very atypical for Denmark, mind you! 😄
it’s mostly Java and C# in the state-owned IT solutions, I’d venture
this project is a very different beast indeed
but Denmark is great regardless 😛
@gadfly361 Ok, interesting, the reloads don't work for me as well, and deref'ing the atom doesn't change anything as well
I tried changing the multimethod to a case statement (like i use in re-frame-template) .. but that didnt work either. what are you using for that?
(he said, with great prejudice)
about Visual Basic, I mean
gotta go, will check up on this discussion later
@mrchance are you doing something like this by chance?
(defn ^:export main []
(dev-setup)
(app-routes)
(reload))
(main) ;; <-- adding this
because then figwheel would call that everytime on save and the reloading would work as expected
The only thing that's different apart from that is that I parameterized the app-routes function, but I don't see how that would cause re-renders
@mrchance @gadfly361 I'm having trouble figuring out what problem you guys are pursuing?
@reefersleep we're trying to figure out why figwheel reloads my code with just :figwheel true
while it requires an explicit reload in the template
I'll give it a go when I get the chance as well
btw @mrchance , I got an arity error when I did
user> (defmulti page identity)
#'user/page
user> (defmethod page :home [] "sweetness")
#multifn[page 0x48e10697]
user> (page :home)
ArityException Wrong number of args (1) passed to: user/eval44477/fn--44478 clojure.lang.AFn.throwArity (AFn.java:429)
but not when I did
user> (defmethod page :home [_] “sweetness”)
#multifn[page 0x48e10697]
user> (page :home)
“sweetness”
I haven’t seen a use case for defmulti/defmethod yet that was nicer than map lookup
oh yeah, you’re right!
I thought I was in my cljs repl, but I was actually in the clj one
I still get tripped up by cider/figwheel starting two repls, even after working with it for a year
maybe I just don’t grok multiple dispatch yet 🙂
I didn't use the cljs repl for a long time, since figwheel is so awesome and the piggiebacking setup was so tedious
But still, good find, I think the template should be changed to the correct arity defmethods
And regarding multiple dispatch: Another big advantage that I forgot is that multimethods are open, not so easy to implement with a map lookup
I get that, but aren’t you doing an app where you own the lookup yourself?
I’m down with the whole expression problem solution thingey, though I haven’t directly benefitted from it myself
hello, I'm getting this error WARNING: JSC_JS_MODULE_LOAD_WARNING. Failed to load module "react" at <...>/experiments/node_modules/create-react-class/index.js line 13 : 4
woah, I didn't even know that's possible (strings in require form). I don't think it's correct though, you should check https://clojurescript.org/reference/dependencies#external-javascript-libraries for how to include foreign libs
Basically, check if there is a cljsjs library for what you want, and if not, provide some extra info in project.clj
What's your source for the string form? I don't think it's supposed to work that way
Then I think you need to follow https://clojurescript.org/reference/dependencies#bundling-javascript-code, with a :foreign-libs
key pointing to your node_modules
https://clojurescript.org/guides/javascript-modules <- maybe this is helpful as well
Hm, interesting, this post mentions the string form as well: https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules
but you can do that with page
being a regular function, too
I am apparently really against multimethods 😄
@mrchance it seems that like @gadfly361 , I cannot get figwheel to reload on file changes properly with
:cljsbuild
{:builds
[{:id “dev”
:source-paths [“src/cljs”]
:figwheel true
maybe you have some project.clj
cache lying around somewhere? Or maybe you have magic fingers. Who knows 🙂
and btw, my CIDER setup did not work with that template. I needed to do lein figwheel
in the terminal.
Interesting, I had that problem too, but only because I had underscores in my project name
And it doesn't reload for me in the standard setup as well, but it does with the project I needed your help with
I have no underscores, so dno
love that emoticon
that’s a first for me, that initialism
Here’s my map version, @dimovich :
(def state (r/atom :page-1))
(defn page [lookup-key]
(let [pages {:page-1 [:div “page 1”
[:button {:on-click #(reset! state :page-2)} “open”]]
:page-2 [:div “page 2”
[:button {:on-click #(reset! state :page-1)} “close”]]}]
(get pages lookup-key)))
(defn index []
[page @state])
Here is my equivalent version for your version @reefersleep 😉
(def page
{:page-1 [:div "page 1"
[:button {:on-click #(reset! state :page-2)} "open"]]
:page-2 [:div "page 2"
[:button {:on-click #(reset! state :page-1)} "close"]]})
yeah 🙂
I don’t assume keyword-as-ifn-functionality in these chat sessions
or map-as-ifn
though I use it all the time 🙂 it’s just that it can be a source of errors and confusion
yeah… or you’re binding “stuff” to symbols and assuming (wrongly) that “stuff” is always something that implements ifn for lookup
not that this happens often, in my experience
but I only really use keyword-as-ifn when I’m referring to the keyword literal in code
that “Clojure is the least sucky language” quote really fit this entire chat session of ours - we’ve come upon and discussed a lot of ambiguousness and caveats in Clojure, Clojurescript, figwheel, leiningen, cider and reagent!