This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-29
Channels
- # aatree (1)
- # admin-announcements (7)
- # announcements (3)
- # beginners (125)
- # boot (164)
- # braid-chat (8)
- # cider (26)
- # cljsrn (37)
- # clojars (3)
- # clojure (162)
- # clojure-argentina (1)
- # clojure-art (2)
- # clojure-berlin (5)
- # clojure-czech (3)
- # clojure-ireland (1)
- # clojure-miami (1)
- # clojure-norway (9)
- # clojure-russia (47)
- # clojurebridge (1)
- # clojurescript (151)
- # community-development (1)
- # conf-proposals (80)
- # core-async (15)
- # core-matrix (1)
- # cursive (66)
- # datomic (26)
- # emacs (17)
- # events (10)
- # funcool (59)
- # hoplon (43)
- # incanter (2)
- # jobs (10)
- # ldnclj (8)
- # lein-figwheel (18)
- # luminus (1)
- # off-topic (19)
- # om (144)
- # onyx (167)
- # overtone (9)
- # parinfer (12)
- # pedestal (1)
- # proton (158)
- # re-frame (139)
- # reagent (48)
- # test-check (19)
- # testing (43)
@shriphani: no problem ๐
Does reaction
notice ratom derefs in a function that's called in the reaction
form? I.e. (def f [] (:foobar @db)) (def reactive-f (reaction (f)))
- is reactive-f updated if the db
ratom changes? Or do I have to write (def reactive-f (reaction (:foobar @db)))
?
I'm trying to make an event mouse-down that doesn't loose the focus (i.e when I click on the element the focus stays where it is), but this previous snippet is not enough
@yenda: I'm not sure if it's the case for you, but I had the scenario once where i wasn't careful enough in my react keys and re-rendering of components, so when I dispatched an event, it updated the model, which re-rendered my component by removing the DOM element (text box in my case) and creating a new one. I that case, the focus was lost.
mhm maybe right that must be the reason I lose the focus, I do have keys but I am changing the content of an input field that has focus so it probably does rerendering
it is possible, however, to update an input field without the focus changing:
(frame/register-sub
:field-value
(fn [db] (reaction (:field-value @db))))
(frame/register-handler
:inc-field
(fn [db _]
(update db :field-value inc)))
(frame/register-handler
:update-field
(fn [db [_ v]]
(assoc db :field-value v)))
(defn main-panel []
(let [data (frame/subscribe [:field-value])]
(fn []
[:input {:type "text"
:on-mouse-down #(frame/dispatch [:inc-field])
:value (or @data 0)
:on-change #(frame/dispatch [:update-field (-> % .-target .-value int)])}])))
mine is on a different element it inserts the value of the element you click where your pointer has focus, but after that it loses the focus
do you mean the following is happening: - element 1 has focus - click element 2, event updates data for element 1 - element 2 gets focus
I have not used React.js without a wrapper(om/reagent) but is it fair to say Reagent is more concise than pure JS react with jsx?
@yenda: hmm, not sure about that then. it seems like that's just the standard behavior of the browser. maybe you could call (.focus elem)
after you click.
@yenda: I had mentioned form-3 in order to get a handle on the dom element, but .-activeElement works also. Putting that focus call in a timeout makes it work:
{:on-mouse-down (fn [e]
(let [el (.-activeElement js/document)]
(frame/dispatch [:inc-field])
(js/setTimeout #(.focus el) 10)))}
so I assume the timeout is because it takes some time for the unfocus event to propagate ?
i just got the idea from some google searching, it seems in jQuery land that's how people are doing the same thing
there is probably something wrong because now I seek mutability to be able to set the carret position where it should be ๐
yeah, like i said, i'm not sure if it's a best practice. however, i don't know if storing dom focus in the app state is typical either. it seems more like local state. but i guess it depends on the app. it seems like it could get complicated if every change of focus had to update the app state
My problem space is similar to a text editor that would allow the user to insert special symbols in a input area without loosing the focus and career position to carry on typing
career position? so... lose focus and get fired? ๐
Hi guys I have a few issues with my reagent setup. Thereโs a POST endpoint which complains about the CSRF token. I have set anti-forgery to false using: https://www.refheap.com/114239 but the complaint persists - any ideas?
@shriphani: Can you post the error message too?
@shriphani: My bet would be that it's the route definition on the endpoint that's the problem, not your CLJS - I had a lot of trouble getting it to work and tried a lot of different things. Here's what I ended up with, pretty sure there's some overlap between some of the stuff and not sure how good it is, but maybe something in there will help you get rid of your error. https://www.refheap.com/114241
Whoops missed one definition that I think was important too https://www.refheap.com/114242
@shaun-mahood: I got it to work. So the reagent template drops a middleware.clj
in end/dev/clj/proj_name
where it wraps your app up in all sorts of stuff - placing the forgery bits there caused ring to pick things up.
Oh cool - I didn't realize the reagent template had a Clojure component. Anti-forgery can be such a pain when you just expect things to work.
yea this is a tiny internal tool so I was losing my shit when it started taking too long. anyway thanks for the help -really appreciate it.
That's awesome