This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-09-28
Channels
- # admin-announcements (1)
- # announcements (1)
- # beginners (17)
- # boot (29)
- # cider (8)
- # clojure (87)
- # clojure-czech (2)
- # clojure-nl (2)
- # clojure-russia (108)
- # clojurebridge (9)
- # clojurescript (34)
- # cursive (5)
- # datascript (15)
- # devcards (14)
- # editors (6)
- # hoplon (121)
- # jobs (7)
- # ldnclj (22)
- # onyx (2)
- # re-frame (31)
- # reagent (43)
- # testing (2)
hi all - is it safe to create cursors inside a component or should they be created in the outer let in a form-2 component or global name space?
it seems (according to docs in the github issues (specifically https://github.com/reagent-project/reagent-cursor/issues/14) that it is fine.
If you create the cursor in a component, won’t it be recreated every time the component re-renders?
that was the motivation for the question, but the comments in that issue lead me to believe that is OK….
which comments?
(sorry @erik_price I didn’t notice your reply)
this comment - https://github.com/reagent-project/reagent-cursor/issues/14#issuecomment-71561365
I’m not an expert in Reagent, but my reading of this is that any time the grid-a
ratom changes, grid-component
will re-render, and recreate the subcursors. So the benefit of using subcursors here seems to be limiting cell-component
’s knowledge of the entire grid-a
data structure to only the substructure. But I don’t think there is any performance win, as there would be if the subcursors were constructed “up front” and then closed over by the rerender function.
Maybe I’m wrong?
I still don’t get how do I render a checkbox that changes the atom but does not re-render every time its checked ;/
@gadfly361: https://gist.github.com/nooga/2da3bff215f0f7d2adb3 I tried something like this
and the result, as expected, is :tasty toggling, but with re-render after every click on any checkbox
I think by dereffing in [items @state] you are forcing a rerender of items each time state changes
I'm not sure i undersrand what the desired behavior is, without a rerender how can the checkbox get checked?
@nooga is the problem that all checkboxes get re-rendered instead of only one that has been changed?
“looks clunky” – you mean the checkbox flashes briefly, because the item
component results in the <div><span><input…
being removed from the DOM, then a new one created and added to the DOM?
or do you mean something else?
@erik_price: that’s exactly what I mean
I thought so. But it seemed like there was some confusion on that, so I figured I’d have you clarify. But I don’t know the solution for this.
i thought there’s maybe way to tell reagent that this checkbox is bound to this bool and it would work both ways
This isnt a small example unfortunately, but i would take a look at this: https://github.com/tastejs/todomvc/tree/master/examples/reagent
So if you have something like an ID (in reagent atom not a dom id) to the path of your checkbox, you can use 'update-in' and go directly to the path of your checkbox in your reagent atom when swapping. This avoids the need to go through the whole list.
@nooga: for the flashing problem, this does not seem Reagent-specific. Maybe you should just not use checkboxes, but some icons instead.
@nooga: I'm thinking that preventDefault() may also do what you want