This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-03
Channels
- # admin-announcements (1)
- # beginners (4)
- # boot (1)
- # chestnut (2)
- # clara (1)
- # cljs-dev (8)
- # cljsjs (50)
- # clojure (40)
- # clojure-austin (3)
- # clojure-brasil (3)
- # clojure-canada (1)
- # clojure-gamedev (2)
- # clojure-italy (3)
- # clojure-russia (19)
- # clojure-spec (14)
- # clojure-uk (1)
- # clojurescript (60)
- # core-async (4)
- # cursive (4)
- # datomic (3)
- # editors-rus (2)
- # emacs (4)
- # events (1)
- # figwheel (2)
- # flambo (4)
- # hoplon (94)
- # jobs (4)
- # leiningen (3)
- # om (9)
- # onyx (64)
- # re-frame (86)
- # reagent (52)
- # spacemacs (4)
- # test-check (1)
- # yada (31)
Maybe the reason is obvious to experienced users, but not to me. Just started clojurescript. So any pointers would be appreciated!
Hi @kiko. What are you trying to do in this code? Cycle through the first 5 names?
@shaun-mahood Not quite. This code just renders [:div hello from @name] 5 times in row. This just simplify the problem I am having using subscribed value inside a loop.
[search-bar] has simple input form which dispatch handler to associate :name to db.
so when (:name db)
is "re-frame"
, the result would be:
Hello from re-frame
Hello from re-frame
Hello from re-frame
Hello from re-frame
Hello from re-frame
The problem is @name won't get updated when the :name in db changed. However, once put @name outside of the for loop. It gets updated. @name in all those 5 rows generated by loop get updated. Am I making this clear?
Yep, just had to step away for a second. It will take me a minute to write up a decent answer.
So there’s a couple things going on here. The main one is that your loop really should be outside of the entire component - the value in :name
is the string “re-frame”, so when you dereference it with @name
you are going to get the value “re-frame” as above. Within the loop, all that is happening is that you are getting the same value 5 times - exactly what you are seeing. Now when name changes, your subscription will see that change and update the view with the new value - this is fundamentally how re-frame works. So at any point in time, the value of @name
in your code will be a single string, and when it updates with a new value it will just change to a different single string.
@kiko: One other note, your (for [x (range 5)]…
code has a separate issue - the internal code doesn’t change based on the value of x at all. So if @name
were a sequence (say it was @names
and the values were `[“re-frame” “redux” “elm” “zelkova”], the code you would be looking for would be along the lines of
@shaun-mahood :name is not a sequence. The problem is Now when name changes, your subscription will see that change and update the view with the new value
is not happening inside for loop.
Ok, then what is the purpose of the for statement?
I'm adding to load some stuff from my api, and to do so, i'm trying to load [day8.re-frame.http-fx]
I've added the dep to my project file and included that in the require section, but unfortunately I'm getting some errors
@shaun-mahood I was originally doing
(for [[category products] dataset]
... <show category> ...
(for [product products]
... use subscribed @value here ...
@curlyfry: I was just informed that all you should need to do to update from 0.7.0 to 0.8.0 and get it to build is 2 find and replaces across the project
- replace register-handler
with reg-event-db
- replace register-sub
with reg-sub-raw
No need to change any arguments or anything. Sorry for the confusion!
The purpose of the for statement is showing the issue in shorter. The issue is subscribed value doesn't get updated inside for loop.
@kiko: Ok, that makes more sense. In that code example, is products
a sequence?
@shaun-mahood yes, dataset is like {category1 [prodA prodB] category2 [prodC prodD]}
Also here is a working tree of the simplified example above. <mailto:[email protected]|[email protected]>:kiko/rf_playground.git You will see the 'update' issue I am trying to explain.
@dpsutton: Not the best answer, but when I run into problems like that I usually run lein cljsbuild dev
(or whatever your profile name is) manually - most of the time it will give me an error that was being swallowed for some reason.
@curlyfry: Also, the old syntax still exists in 0.8.0 and does give a deprecation message already. Really sorry for the confusion on that one, I read through the code and my brain just skipped that part apparently. So you should be able to just update your dependencies and everything should work with no changes!
@kiko: Thanks, I’ll take a look
@dpsutton I'd just do a lain clean
and try again. Are you sure you did step 1 in https://github.com/Day8/re-frame-http-fx#quick-start-guide
@kiko: When you run that example in figwheel, can you see the errors in Chrome devtools?
@kiko: There should also be a warning along the lines of “Reactive deref not supported…”, do you get that one too?
Yeah that one should fix it - it did for me
@shaun-mahood It did it for me too. I felt so ashamed....
@kiko: Don’t worry about it! There are a lot of things unique to CLJS, Reagent and re-frame and it can be pretty difficult to figure out why things aren’t working when getting started with them, particularly if they are all new to you. I’ve made worse mistakes than that one this week, and in areas where I have a pretty decent amount of experience. 🙂
Thanks a lot, thanks taking your time helping me (to not give up!). Not only whole new syntax but also think in FP is totally different to me. But I really have fun writing web stuff in CLJS than javascript. Thanks to you all who are making this happening. 🙂
super bizarre. I can load my db namespace, but when i require it it says its not a valid namespace
Do you have some funny mixture of cljc and cljs files ?
What "option profiles" did you use ? Eg: +secretary
and +test
Yeah, I'm puzzled
@dpsutton: Wow, you’re having really bad luck with this. It really shouldn’t be that hard!
Which isn’t to say I haven’t run into the same types of problems with other things, but it’s definitely a pain.
looking through the cider code, it looks like it knows all of the incantations to crank up the repl, don't have to set anything
@dpsutton did you try in-ns
your namespace and then just referring to the symbols directly?
i had the code mentioned on re-frame (or maybe somewhere else) about setq'ing a cider-clojurescript repl blah blah where it was a do form that required figwheel and started it up