Fork me on GitHub
#re-frame
<
2016-09-03
>
kiko02:09:23

Maybe the reason is obvious to experienced users, but not to me. Just started clojurescript. So any pointers would be appreciated!

shaun-mahood02:09:15

Hi @kiko. What are you trying to do in this code? Cycle through the first 5 names?

kiko02:09:12

@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.

kiko02:09:53

[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

kiko02:09:10

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?

shaun-mahood02:09:27

Yep, just had to step away for a second. It will take me a minute to write up a decent answer.

shaun-mahood03:09:31

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.

shaun-mahood03:09:44

@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

kiko03:09:02

@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.

kiko03:09:03

Sorry for the confusion. I'm not trying to display the names from collection.

shaun-mahood03:09:48

Ok, then what is the purpose of the for statement?

dpsutton03:09:38

I'm adding to load some stuff from my api, and to do so, i'm trying to load [day8.re-frame.http-fx]

dpsutton03:09:00

I've added the dep to my project file and included that in the require section, but unfortunately I'm getting some errors

dpsutton03:09:12

and of course restarted the repl. Are lein clean runs necessary when adding deps?

kiko03:09:27

@shaun-mahood I was originally doing

(for  [[category products] dataset]
 ... <show category> ... 
(for [product products]
... use subscribed @value here ...

shaun-mahood03:09:57

@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!

kiko03:09:55

The purpose of the for statement is showing the issue in shorter. The issue is subscribed value doesn't get updated inside for loop.

shaun-mahood03:09:42

@kiko: Ok, that makes more sense. In that code example, is products a sequence?

kiko03:09:39

@shaun-mahood yes, dataset is like {category1 [prodA prodB] category2 [prodC prodD]}

kiko03:09:34

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.

shaun-mahood03:09:04

@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.

shaun-mahood03:09:33

@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!

shaun-mahood03:09:34

@kiko: Thanks, I’ll take a look

mikethompson03:09:15

@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

shaun-mahood03:09:10

@kiko: When you run that example in figwheel, can you see the errors in Chrome devtools?

kiko03:09:11

I see warnings for missing keys

shaun-mahood03:09:13

@kiko: There should also be a warning along the lines of “Reactive deref not supported…”, do you get that one too?

kiko03:09:44

Ohh, sorry i missed that.

shaun-mahood03:09:55

Yeah that one should fix it - it did for me

dpsutton03:09:55

i have no idea what i've done differently but it seems to have worked

kiko03:09:18

@shaun-mahood It did it for me too. I felt so ashamed....

shaun-mahood03:09:01

@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. 🙂

kiko03:09:56

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. 🙂

dpsutton04:09:33

lots of moving parts

dpsutton04:09:43

i think its now looking for a file in the java arena

dpsutton04:09:26

super bizarre. I can load my db namespace, but when i require it it says its not a valid namespace

mikethompson04:09:39

Do you have some funny mixture of cljc and cljs files ?

dpsutton04:09:21

i'm about ten lines in on the re-frame template

dpsutton04:09:06

yeah that's the template

dpsutton04:09:57

yeah i can go in the ns, look at my default-db

mikethompson04:09:31

What "option profiles" did you use ? Eg: +secretary and +test

dpsutton04:09:41

cider and secretary

dpsutton04:09:22

I've added two new deps for ajax and the re-frame-http-fx

dpsutton04:09:56

after adding them, i evaluated my handlers ns and kaboom, no db ns found

dpsutton04:09:49

and its giving me java.illegalArgumentExceptions which feels wrong

mikethompson04:09:03

Yeah, I'm puzzled

dpsutton04:09:31

just did a lein deps, lein clean, lein figwheel dev

dpsutton04:09:41

we'll see if it runs from lein without cider/emacs

dpsutton04:09:11

having people to commiserate is half the battle

dpsutton04:09:35

restarted emacs, now can't find the figwheel infrastructure

dpsutton04:09:40

this is really tough

shaun-mahood04:09:15

@dpsutton: Wow, you’re having really bad luck with this. It really shouldn’t be that hard!

shaun-mahood04:09:49

Which isn’t to say I haven’t run into the same types of problems with other things, but it’s definitely a pain.

dpsutton05:09:21

yeah. just feels fragile

dpsutton05:09:28

really want to get it up and running

dpsutton05:09:45

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

johanatan05:09:46

@dpsutton did you try in-ns your namespace and then just referring to the symbols directly?

dpsutton05:09:52

hmm, says starting a rhino repl. that's a new one to me

dpsutton05:09:26

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

dpsutton05:09:25

oh, and that seems to be the piggieback version which is definitely wrong

dpsutton05:09:14

ah that's not autodetected, but set by a defcustom

dpsutton05:09:24

one tangential problem solved

johanatan05:09:29

i haven't setup cider in my setup but figwheel pretty much just worked out of the box

dpsutton05:09:53

yeah, it has a var for the default repl and issues its own start up commands

dpsutton05:09:57

rhino is the default

johanatan05:09:57

are you using spacemacs?

dpsutton05:09:59

just changed that over

dpsutton05:09:08

no just emacs from 25.5.whatever

dpsutton05:09:22

it also parses the output looking for localhost:digits to offer to let you visit it

dpsutton05:09:49

awesome, setting that defcustom has us cooking with fire

dpsutton05:09:56

lets see if we can load hte handlers namespace

dpsutton05:09:03

ps, everybody here with me yall are awesome

dpsutton05:09:43

well, the plot just thickened

dpsutton05:09:57

it may have been fine this whole time

dpsutton05:09:14

i've been using C-u C-c M-z to load the namespace that point is in

dpsutton05:09:22

i wonder if this causes both repls to try and load

dpsutton05:09:34

but when i used (in-ns cljstomahawk.handlers) it worked

dpsutton05:09:11

hmm, i wonder if that's just a bug in cider

dpsutton05:09:28

literally, loading the file causes it, but it looks like everything works