This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-11
Channels
- # aws (15)
- # beginners (55)
- # boot (116)
- # bristol-clojurians (2)
- # cider (4)
- # cljs-dev (439)
- # cljsrn (14)
- # clojure (135)
- # clojure-argentina (3)
- # clojure-czech (4)
- # clojure-italy (60)
- # clojure-russia (1)
- # clojure-spec (48)
- # clojure-uk (42)
- # clojurescript (170)
- # cloverage (11)
- # core-async (19)
- # cursive (13)
- # datomic (48)
- # emacs (2)
- # graphql (3)
- # hoplon (8)
- # jobs (1)
- # jobs-discuss (5)
- # klipse (11)
- # luminus (5)
- # lumo (5)
- # mount (48)
- # off-topic (96)
- # om (17)
- # onyx (14)
- # parinfer (30)
- # protorepl (1)
- # re-frame (90)
- # reagent (2)
- # remote-jobs (1)
- # spacemacs (12)
- # specter (20)
- # uncomplicate (1)
- # untangled (65)
- # vim (2)
- # yada (8)
@mikethompson Can you give me some direction? ^
To be clear, wee're talking about: https://github.com/Day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc#L186
Yes, although I could write my own interceptor.
While keeping this sentiment in mind: https://twitter.com/nathanmarz/status/879722740776939520
So the way we use enrich
is to add an interceptor to EVERY state changing event handler
and in that interceptor we recompute completely the current warnings or errors ...
.... placing that "state" (warnings and errors) into app-db
And we do this as an alternative to "incrementally" calculating how the latest event changed the warnings and error state
So ... no incrementalism ... we do a full re-compute all all errors andwarnigns each time. Because it is so much simplier to do it that way
(At the cost of inefficiency)
So ... strategy is that we put the re-computation into EVERY event handlers which might make a change which changes the current warnigns and errors being displayed
Which is fine, but (for example) if your handler adds :http-xhrio to the effect map, before the validation is run, how do avoid submitting to the server. I feel like I’m missing a step somewhere.
Okay, you are adding a step which we don't have ... a submit In our apps, we're not submitting. We're just reporting current warnings and errors
So ... in your case ....
Use before?
I’m know I’m about to experience some enlightened moment.
No before
happens before the event handlers is run
Sounds like you have a form-ish situation. Data entry, then hit the submit button.
Yes, without a form element, but yes.
So the enlightenment is simply that when i was describing our use of enrich
, the usecase was not form-ish
Ok, so if you are not using a form-ish flow, how so you manage state synchronization with a server? What occurs in the flow to say, save this state somewhere?
Yeah, so that's the point, we're not talking to the server
We have very rich SPA which seldom talk to servers
Ah. I see.
So, in my case, where would you do the validation?
So, I'm assuming you have: 1. checking/validation to do after every bit of data entry (dispatched) 2. checking/validation to do when the user presses the "Send to Server" button ?
And the checking/validation part is the same for 1 and 2
For us, the warnings and validation involves interplay between various on-screen widgets. But I'm guessing that's not the case for you? I'm guessing you just want to be sure they have entered all mandatory values, etc.
And that the emails are in the correct form?
I'm just trying to get clear on your usecase
I’m building a react-native app using re-frame. User enters an email address and clicks Next, then enters a password and clicks Next. I want to validate in a few different places.
But each time you are validating just one item
I could do it in the handler, or in a before, but in your various mentions on enrich online you say to validate after the handler.
I want to make sure I’m using the different re-frame steps correctly.
Yeah, so my mentions are because we have a complicated desktop application with many widgets and as the user interacts with nay one of them, the error/warning state of the entire app changes.
hence my comments before about https://twitter.com/nathanmarz/status/879722740776939520
We don't try to incrementally figure out what any one interaction means, we just recompute the entire warning/state
So ... back to your issue ...
... after all this ... i think you should just be doing the error detection in your event handlers
Sorry to have taken so long to cycle back to that point
You are effectively checking on thing at a time
Is the email correctly formated?
enrich
is really just a way of post-processing the current state (in our case, for warnings) ... so it is just a way of factoring out some post processing which is shared across multiple event handlers. But that is not your usecase. You have different error checking after each event handler
after? Don’t you mean within the handler or before?
In our case we use enrich
to do it :after
. In your case, within (but at the end)?
I do hope I'm helping here
Haha. Somewhat. I really appreciate the effort and time though.
Do you know of a good open source re-frame app that demonstrates some or all of this? Not something simple but a little more complex. There are quite a few moving pieces in re-frame and knowing which piece or step should be responsible for what is difficult for a newbie.
Something closer to my use case than yours.
Perhaps have a look through the Resources list?
Of course. Thanks.
Thanks again for taking the time.
Yeah, cheers.
I'm using re-frame 0.9.4 and when an event is handled that doesn't change the app-db, the subscriptions that depend on app-db directly fire nonetheless. Anyone else have this too?
An when an actual change happens, some subscriptions fire twice - am I somehow circumventing deduplication?
Hi, I’m not even sure if this is the best place to ask this lol, but basically have been working through stuff with Datomic on the server, and reagent/re-frame. And I’m getting to where everything seems to be pretty elegant and work together well, but my REST interfaces (or perhaps the way I’m doing them) just feels clunky compared to everything else. Was just curious to know what people are using. I just saw Walmart’s Lacinia (GraphQL in clojure) which looks interesting
I've been using jsonapi
I'm not familiar with HATEOAS but a quick googling tells me "maybe" lol
yeah i just looked at the jsonapi spec, seems to be a bit of formalism, etc around doing it consistently, etc
i like the GraphQL approach of letting the client ask for what it wants in the shape that it wants it
yeah it's really just a spec around using JSON payload for REST
I like the idea of GraphQL but I don't like that you have to specify all fields that you want
yeah i’ve historically done a lot of Java, etc. There’s a Spring HATEOAS lib, that helps you build stuff like what’s in jsonapi
so you can't just ask for an object with all attributes
I'm not using any clojure lib for jsonapi
idk if there is one
@mbertheau
1. First point (not answering your question yet) be sure to layer your subscriptions so the Layer 1 subscriptions are trivial "accessor" kind. They don't do any computation. https://github.com/Day8/re-frame/blob/master/docs/SubscriptionInfographic.md
2. Now, answering your question: any update to app-db
will trigger Layer 1
subscriptions. Even if the db
is identical?
to last time. If it is important to stop this, then use an -fx
kind of event handler and don't return a :db
effect (then the app-db will not be updated at all)
Ie. a use reg-event-fx
kinda event handler and, in that handler, don't return a :db
key when you want no change.
But, now, I'm thinking about this a bit more, re-frame should really detect this, and help out
(reg-sub :my-expensive-sub (fn [db [_ params]] (if-let [result (:result db)] result (dispatch [:event-expensive-work params]))))
^ It is possible?
(reg-sub :my-expensive-sub
(fn [db [_ params]]
(if-let [result (:result db)]
result
(dispatch [:event-expensive-work params]))))
@souenzzo in slack, you can post correctly formated chunks of code by using three ticks.
<three ticks>
lines of code
<three ticks>
No, means the reader has to work harder
No, you should never dispatch
in a subscription handler