Fork me on GitHub
#reagent
<
2016-10-28
>
cl0jurian11:10:05

Hi guys. I ran into this issue today. http://stackoverflow.com/questions/40304349/how-to-access-reagent-components-children-elements-correctly I'm already tampered by that thing. Glad I found reagent channel. Someone please give me a hint regarding that issue. Thanks

mac12:10:40

@cl0jurian A bit hard to understand exactly what the issue is. Is a request sent at all or do you get an error or?

cl0jurian12:10:28

@mac Sorry Its not much clear. My problem is the input element's on-change event handler function cannot get the chosen file.

cl0jurian12:10:30

@mac when I using this variable it contains Window element

cl0jurian12:10:02

@mac hope that make sense

mac12:10:29

@cl0jurian Try this: (-> % .-target .-files (aget 0))

cl0jurian13:10:31

@mac I added that line as this (-> el .-target .-files (aget 0))

cl0jurian13:10:00

@mac but an error comes "Uncaught TypeError: Cannot read property 'files' of undefined"

mac13:10:27

@cl0jurian I think you should avoid this whole this business and use (-> e .-target .-files (aget 0)) - as far as I can tell there is no reason to use this or this-as here.

cl0jurian13:10:38

@mac ya I guess what you saying makes sense to me. ok I will edit and check.

cl0jurian13:10:14

@mac Well now we are in business. You saved me 😄 thank you so mcuh @mac

mac13:10:57

@cl0jurian You are welcome. I posted it on stackoverflow too. While you are at it, why are you creating an atom (state_) and immediately dereffing it? and why are you let binding the component to ad-box instead of just returning it?

codxse14:10:24

hi guys, I have a basic question. I am confused how to use reagent atom. Let say we a have an atom (def my-atom (r/atom {:number 0})) if I want access that atom from my fn I just access it by @my-atom. for example (defn component [] [:p (@my-atom :number]) But.. why it doesnt work when I want swap. like (swap! @my-atom update :number inc) it does work when I replace @my-atom to my-atom.

codxse14:10:09

so my question, when to use @ and do not use @?

lvh14:10:06

codxse: my-atom is the atom itself; @my-atom is the current value it holds

lvh14:10:28

codxse: the value of swap! is to operate on the atom directly, atomically, even if someone else tries to do the same concurrently

lvh14:10:38

codxse: it’s swap!‘s problem to give the fn you pass it the current value

codxse15:10:14

so, @my-atom is like mutate directly, right? it doesn't hold previous value? @lvh

lvh15:10:59

@codxse lowercase L not uppercase i 😉

lvh15:10:14

@codxse no mutation going on when you do @

lvh15:10:24

@ is “give me the current value” — that value is typically immutable

lvh15:10:42

technically you can put a mutable value in an atom, I think — but that’s awful, bad, don’t do it, none of the guarantees hold, &c

codxse15:10:24

thanks @lvh, make me clear

cl0jurian17:10:53

@mac I want to do here is keep track of the preview images of 8 upload boxes. what do you think @mac is it a good approach ?

cl0jurian17:10:22

@mac and thanks for updating sof

mac17:10:44

@cl0jurian Not sure what you mean by "keep track of".

cl0jurian18:10:10

@mac my intension is to update these upload boxes according to user's behavior. user could upload and remove uploaded pic etc. Havent coded that part at the moment. May be its not a good move. Im just new to Reagent/React and also to Luminus. Hope you understood what I trying to do here @mac . But Im not sure my approach isn't good.

mac18:10:53

@cl0jurian Well an atom could be a good way of controlling what image is shown, I was just confused as to why you would do what you do in the code included in the example.

cl0jurian18:10:46

@mac I put a vector of image names and map among the boxes. Im glad its a good idea. So I can keep working on it. 🙂