This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-14
Channels
- # architecture (5)
- # beginners (36)
- # boot (3)
- # cider (89)
- # clara (35)
- # cljsrn (6)
- # clojure (123)
- # clojure-dev (15)
- # clojure-italy (9)
- # clojure-nl (14)
- # clojure-spec (11)
- # clojure-uk (192)
- # clojurescript (27)
- # cursive (22)
- # data-science (1)
- # datascript (1)
- # datomic (31)
- # defnpodcast (1)
- # duct (1)
- # emacs (9)
- # fulcro (2)
- # graphql (16)
- # jobs-discuss (10)
- # juxt (1)
- # keechma (7)
- # mount (4)
- # off-topic (83)
- # onyx (8)
- # pedestal (5)
- # portkey (1)
- # re-frame (44)
- # reagent (29)
- # reitit (4)
- # remote-jobs (1)
- # ring-swagger (1)
- # rum (24)
- # shadow-cljs (1)
- # spacemacs (30)
- # tools-deps (6)
- # vim (23)
@eoliphant Can I use them for inspecting re-frame in clojure ? I thought that is only available for browser .
@shakdwipeea What are you trying to do? I have difficulty imagining how re-frame would be useful without a browser and clojurescript.
I am experimenting with re-frame for communication b/w clojure and clojurescript. I have created an effects handler which send the data to my server using web sockets. This data is generally of the form [:some-event data], on the server upon receiving this data I am doing a dispatch for that event. Now I have event handlers defined in clojure which is then triggered, the server can also communicate to client in a similar problem. The works well for a few times, but after some time my event handlers on the server are not being called even after dispatch.
component for running it on clojure https://github.com/entranceplus/snow/blob/master/src/snow/comm/core.clj#L59
Hi. I'm creating a form 3 component and was wondering, whether it's considered bad practice to trigger side effects in reacts lifecycle hooks. On component-did-mount
, I bind a js event handler and call a js function and on component-did-update
I trigger a change event on one dom node. Should those be effects or do you think it's fine?
There are certainly times when it's unavoidable to get at specific features. In my business apps it's pretty rare I jump to it.
Is there a specific example which you have in mind?
mounting scroll handlers on window - better to do in react lifecycles, high-level logic like :user-closed-popup
- better in effects.
Yes, avoiding side effects as much as possible is obviously the right way to do it, but here I work with existing code. It's about bootstrap-toggle, an open-sourced thing. I need to initialize it in the beginning so it renders and if the state updated, I need to trigger the change event to make it reflect that change in the UI.
Yeah, then you're probably on the right track... except it's always nice to look for a react component to replace old stateful ones.
came to the same conclusion and rewrote the component without jquery. Just reuse the styling 😉
Yeah, exactly
Hi, whats the idiomatic way to set an option as selected in a html select component? Is it (if (= value (rf/subscribe [:selected-value]) "selected" "")?
i think you just need to set the value property of the select input https://reactjs.org/docs/forms.html#the-select-tag
@U6AE62UCT Thats exactly what I was looking for, thank you very much.
ah sorry @shakdwipeea, missed the ‘in clojure’ part
@sveri I think that is one reasonable way,but you need to deref
the subscription. Also, do you mean to set the :selected
property of a <option>
element?
(let [selected @(rf/subscribe [:selected-value])]
...etc...
[:select
[:option (cond-> {} (= value selected) (assoc :selected true)) ...etc...]
...etc..]
)
@mikerod Thanks, thats the way I did it. I was just wondering if there is a more succinct way
I don’t know of anything. You could perhaps make a custom component that encapsulated that behavior
I’ve got this type of subscription:
(re-frame/reg-sub
::is-loading?
(fn [db [_ & path]]
(let [full-path (into [:loading] path)]
(get-in db full-path))))
and then I’m using it like so
(re-frame/subscribe [::subs/is-loading? :sortable :projects])
and it always returns undefined@bravilogy that seems fine
Are you sure that ::subs/is-loading?
is resolving to the same qualified keyword as where you are defining the re-frame/reg-sub
on ::is-loading?
so a button click updates db
and it does this:
(re-frame/reg-event-fx
::reorder-list
(fn [{:keys [db]} [_ path new-items]]
{:db (assoc-in db [:loading :sortable :projects] true)}))
there is the re-frame-10x
which I’m still getting around to exploring more. There is re-frisk
which lets you look at the db state via a click/expand UI widget.
Then you can also just make a subs on the db
and do some REPL prodding at it or prn
s etc
something even weirder here:
(re-frame/reg-sub
::is-loading?
(fn [db [_ & path]]
(let [full-path (into [:loading] path)]
(js/console.log (get-in db [:loading :sortable :projects]))
(get-in db full-path))))
that console.log outputs the correct value 😕umm.. one question. this is how I subscribe to that:
:reagent-render
(fn [items item-view db-path]
(let [is-loading? @(re-frame/subscribe [::subs/is-loading? :sortable :projects])]
(js/console.log is-loading?)
(if is-loading?
[:div "Is loading now"]
[:ul.list-group
(map item-view items)])))