This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-25
Channels
- # bangalore-clj (5)
- # beginners (225)
- # boot (36)
- # cider (1)
- # clara (2)
- # cljsjs (1)
- # clojure (76)
- # clojure-belgium (1)
- # clojure-conj (1)
- # clojure-india (4)
- # clojure-italy (5)
- # clojure-korea (1)
- # clojure-russia (22)
- # clojure-spec (35)
- # clojure-uk (52)
- # clojurescript (67)
- # community-development (17)
- # core-logic (2)
- # cursive (2)
- # datascript (28)
- # datomic (44)
- # emacs (1)
- # funcool (3)
- # hoplon (14)
- # lein-figwheel (2)
- # leiningen (2)
- # luminus (3)
- # midje (3)
- # mount (2)
- # nyc (2)
- # om (54)
- # om-next (1)
- # onyx (30)
- # re-frame (57)
- # reagent (19)
- # ring-swagger (23)
- # slack-help (10)
- # spacemacs (2)
- # specter (1)
- # vim (23)
@tomerweller something like ...
1. the server query (via HTTP?) will be initiated in an event handler, assumidly in response to some event like [:user-clicked-navbar-item 3]
, via something re-frame-http
.
2. This event handler will also set a bit of app state, (assoc db :loading true)
3. When you get the HTTP call response, you save the data into db
into the path, say, :the-data
4. Your subscription will query for both :loading
and :the-data
. It will return nil
or []
while ever :loading
is true, otherwise when :loading
transitions to false
it will return whatever is needed from :the-data
.
@knaman I can't seem to follow your question/problem ... but I can see a problem in your code ... use this instead
(defn edit
[id]
(let [alerts (subscribe [:alerts])
a (filter #(= id (:a %)) @alerts)]
((template) a "Edit")))
Mind you the problem with this approach is that a rerender will be triggered everytime alerts
changes
Without really understanding the context, perhaps better like this ...
(defn edit
[id]
(let [a (subscribe [:alert id])] ;; <-- subscription give a single alert
((template) @a "Edit")))
@mikethompson the problem was rerendering only, not so much to do with any ui issue as it doent affect anything, but kind of bothered me that adding the elements has nothing to do with editing function
Like i said, I'm totally confused about the problem you describe, but I'm afraid I've not got more time to devote right now. So just jumped in with a code related observation
Because some of the code you supplied was broken
@mikethompson no worries, ill give your suggestion a try thanx
@mikethompson are you headed to clojure conj next week?
Sadly, no
Us re-framers attending will pour one out for you. Did you see that there’s a re-frame talk?
Would love to, but there's the tyranny of distance Yes, shaun is giving one (talk)
Is that the first ever talk on re-frame at a conference?
Might be
We're a low profile, gorilla movement
Knuckles on the ground and everything :-)
grassroots movement, very cool 🙂 I am very happy that there is going to be a talk on it, finally!
@mikethompson thanks that helped
next: Is it possible to register a subscription with a dynamic list of input signals?
@tomerweller have you had a chance to read through https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs
That's the best docs currently available on reg-sub
@danielgrosse nothing obviously wrong
But ... it looks as if the problem is in the subscription handler for :title
, right?
You are saying it is not delivering a changing value?
Can't figure out why session-component
takes a session
argument. Doesn't use it.
@mikethompson The example is really stripped down. In the full version, the session object is used. I did find the error. The wrapping function caused the behaviour.
(defn session-component
[session]
(let [title-id (subcribe [:title-id])
session-title (get session @title-id)] ; this represent more the real code
(rf/console :log "session-component " @session-title) ;shows allways the same
[:div @session-title]))
@samueldev @richiardiandrea I’m really looking forward to meeting other re-framers - anyone else coming to the conj?
@andre Exciting stuff! Do you think you could explain a bit more what is happening in the second gif? I don't quite follow what is shown under expand all/Collapse all to the right. Is the event list on the left the history?
@knaman in the first example alerts
will subscribe on every render, probably not what you want in this case. in the second example the subscription is only executed once, and then just the inner fn is executed for each re-render. for more details see https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components
@knaman prior to version 0.8.0, you had to use the 2nd variation (above). But, from v0.8.0 onwards, you can use the 1st version, which is easier. @edannenberg You can read all the details here: https://github.com/Day8/re-frame/issues/218#issuecomment-254718776
@mikethompson ok, i was more thinking about idiomatic ways if any for using either of two ways, right now i use the first variation when i need to sanitize some data coming as argument as i can store it inside a let, and the second one more for ui rendering work
It was the move to a de-duplicated signal graph (in v0.8.0) is what makes this change possible: https://github.com/Day8/re-frame/blob/master/CHANGES.md#080--20160819
@knaman I'd be using the 1st variation all the time now.
There can be subtle issues with the 2nd: https://github.com/Day8/re-frame/issues/218#issuecomment-252470445 (link corrected)
I corrected the link immediately above
@mikethompson i m pretty new to clojurescript, all the docs have example of second tupe
@mikethompson what about subscriptions as @edannenberg pointed out they would be made every time i render
@knaman as the ticket indicates, the decision to officially allow the 1st form was recent. But now it is made, you should absolutely go that way. Much simpler.
The 2nd form will still work, of course. The docs will be migrated to reflect the new decision. .
@mikethompson good to know, was not aware of that. btw, whats your stance on reagent/with-let
?
I never use it
But maybe I should ... i can't even remember what it does
@curlyfry hi, yes ,on the left "history" of all events, and you can click on event and watch event data at the bottom on the right. on the top right the app's state , app-db
for example if app stuck, you can watch current app state and last events data before stuck
@mikethompson basically a shortcut for react lifecycle methods, (ab)used it quite a bit as a shortcut for form-2 so far
one downside is missing IDE support though
@mikethompson regarding dynamic subscriptions, I went over the todos documentations but am still not sure about this specific case. What I have in hand is a subscription that depends on a variable number of subscriptions. i.e, there are two levels of signals. A first signal determines which other signals (o to n) to subscribe to. Do you have any recommendations on how to achieve that?