This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-04
Channels
- # beginners (14)
- # boot (28)
- # chestnut (9)
- # cljsrn (18)
- # clojure (64)
- # clojure-conj (1)
- # clojure-dusseldorf (45)
- # clojure-finland (4)
- # clojure-gamedev (1)
- # clojure-greece (8)
- # clojure-italy (22)
- # clojure-russia (4)
- # clojure-spec (19)
- # clojure-uk (38)
- # clojurescript (49)
- # code-reviews (2)
- # component (12)
- # core-async (3)
- # cursive (3)
- # data-science (2)
- # events (4)
- # fulcro (394)
- # heroku (3)
- # hoplon (16)
- # immutant (11)
- # jobs (5)
- # lein-figwheel (1)
- # lumo (18)
- # off-topic (8)
- # om (11)
- # other-languages (1)
- # overtone (1)
- # pedestal (7)
- # portkey (62)
- # protorepl (1)
- # re-frame (40)
- # reagent (41)
- # ring-swagger (5)
- # spacemacs (5)
- # unrepl (5)
- # yada (12)
I think that has to be done using an fx that puts something in the db
I just watched lambdaisland episode 19 about re-frame and @plexus recommends using form-2 components most of the time (to register subscription only when component is created) - in particular with subscriptions like this: https://github.com/lambdaisland/breakout/blob/master/src/cljs/breakout/views.cljs#L27
(defn blocks []
(let [blocks (subscribe [:blocks])]
(fn []
[:g
(for [[column row color] @blocks]
[block {:row row
:column column
:color color
:key (str row "--" column)}])])))
It looks like a sound advice to me but I'm wondering why the re-frame todomvc app doesn't use this approach, e.g. here: https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/views.cljs#L53
(defn task-list
[]
(let [visible-todos @(subscribe [:visible-todos])
all-complete? @(subscribe [:all-complete?])]
[:section#main
[:input#toggle-all
{:type "checkbox"
:checked all-complete?
:on-change #(dispatch [:complete-all-toggle (not all-complete?)])}]
[:label
{:for "toggle-all"}
"Mark all as complete"]
[:ul#todo-list
(for [todo visible-todos]
^{:key (:id todo)} [todo-item todo])]]))
I consider todomvc app to be a guide for (advanced) beginners so I'm really wondering why that's the case if using form-2 component is best practice.Hi @U06BE1L6T, at the time the video was created this was still necessary. I wrote a blog post about the changes shortly after https://lambdaisland.com/blog/11-02-2017-re-frame-form-1-subscriptions
There was a time when you HAD to use form-2
I'm pretty sure the video was created in that time
Since then, changes have allowed for a relaxation of that
You can use form-1 pretty much all the time these days.
excellent, thanks a lot. last question 🙂. Why to use event handlers like this and not update app-db directly in :block-clicked
event handler? (assuming I don't have a use case for dispatching :update-block
and :remove-block
outside of :block-clicked
event handler) Is there any special reason?
(reg-event-fx
:block-clicked
(fn [cofx [_ col row]]
(if (= (-> cofx :db :color) 5)
{:dispatch [:remove-block [col row]]}
{:dispatch [:update-block [col row]]})))
(reg-event-db
:update-block
(fn [db [_ coords]]
(update db :blocks assoc coords (:color db))))
(reg-event-db
:remove-block
(fn [db [_ coords]]
(update db :blocks dissoc coords)))
Events capture user intent.
To achieve that intent the event handler might modify app-db
or not
Oh, wait. Hold on. I misunderstood your question. Ignore the two lines aabove
I personally would not do the approach above
It is kinda treating a dispatch as a kind of function call
@andre when I upgrade to re-frisk 0.5.0 I get some reader errors (in my code) on namespaced keywords eg #:a{:b 1 :c 1}
(I'm using re-frisk sidecar 0.5.0 too - it's a react native projec)t. I'm guessing something is pulling in an old version of clojure or something like that. Is this somethng you've seen?
hi @U051H1KL1 i haven't made changes related to reader
ah ok thanks. I'm gonna drop back down and have another go later and if I figure out what was going on I'll let you know
@U051H1KL1 where do you see this error?
are you using the clojure 1.9 #:a{:b 1}
syntax?
it's in my code, but only when using re-frisk-sidecar 0.5.0
hold on
also it might be some weird interaction with figwheel or something
(I'm struggling a bit getting my dependencies all lined up, what with figwheel-bridge and everything
it's probably me just being dumb, just wondered if uyou'd seen the error
@mheld - re-com is fantastic if your target is desktop. It is also usable for mobile, but has some issues. I've very recently moved from re-com to Semantic-UI based components for a smoother mobile experience. The canonical CLJS library for this is https://github.com/gadfly361/soda-ash. I've also started writing a wrapper around Soda-ash: https://github.com/deg/sodium that I see you've already tried. (I am still curious about the problem you reported. Do you have any more details?)