This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-01
Channels
- # aleph (4)
- # arachne (24)
- # beginners (231)
- # boot (4)
- # cider (63)
- # clara (36)
- # cljs-dev (57)
- # clojure (195)
- # clojure-dev (12)
- # clojure-gamedev (2)
- # clojure-greece (1)
- # clojure-italy (10)
- # clojure-poland (4)
- # clojure-spec (36)
- # clojure-uk (65)
- # clojurescript (133)
- # core-async (8)
- # core-logic (2)
- # cursive (18)
- # data-science (3)
- # datomic (58)
- # defnpodcast (3)
- # duct (2)
- # emacs (2)
- # fulcro (27)
- # graphql (3)
- # hoplon (18)
- # jobs (2)
- # jobs-discuss (10)
- # jobs-rus (1)
- # lumo (1)
- # mount (6)
- # nyc (2)
- # off-topic (27)
- # pedestal (13)
- # re-frame (71)
- # reagent (105)
- # reitit (4)
- # ring (2)
- # ring-swagger (1)
- # rum (10)
- # shadow-cljs (172)
- # spacemacs (24)
- # sql (26)
- # tools-deps (1)
- # uncomplicate (4)
- # unrepl (51)
- # vim (3)
- # yada (11)
Made some changes https://github.com/CalebMacdonaldBlack/re-frame-interceptors-demo/blob/master/src/cljs/demo/events.cljs
I'm falling in love with re-frame, it's beautiful and clean.. but I have a problem about dispatching syncronusly consider this code
How do I tell re-frame to dispatch ::validate-token-id
first before ::post-exam-token
?? Thanks, appreciate the answers
it already does what you want
Hi, I have a quick question. I’m using reframe with a generic forms app. I have events and subs that set and grab form data [:(get/set)-form-data field-id value]
etc
I’m adding support for calculated fields. so far it’s been pretty straight forward. In my reagent component, I have a mini language for the calculations [:func [:field-id1 …]]
that creates subs for each referenced fields and applies the :func. This works perfecty. so say, my def for :field3
includes the calc def [:add [:field1 :field2]]
The problem that I’m having is that i actually want to set the computed value of :field3 into the db. some how fire the [:set-form-data ..]
event when the subscriptions return new values.
@eoliphant I’ve had similar situations come up before. I struggle to find an elegant solution that that problem. I guess I’d describe it as: It seems valuable and natural to derive some derived data from subscriptions for rendering “on demand” and cached etc. However, there are times when that derived data is something you want to have access to for other “event-side” purposes.
I tend to just think it’s a bad situation I got into and try to figure out if I can work it in on the event side instead. aka, when an event handler gets whatever base data, it derives the value and puts it in the db
Then on the subscription side, it no longer derives anything, it just uses the db value
yeah, for me, the issue is that, in some cases, i need my calculated field a
, to depend of the value of a nother calculated field. So i need the actual value in the db.
The problem I often encounter with “moving things to the event handling side” is that there isn’t really a “signal graph” there. I get into situations (I’ve found) where I have different handlers needing to update things in a way where they keep each other consistent. (different events that may affect various data points that are used in these derived values)
Another possible thing you can do is have the derivation functionality be just a function. Use it in the subscription, and also use it during event handling (with appropriate inputs supplied). I still think that gets clunky and then also loses some of the caching value from subscriptions
Such as what is provided in https://github.com/vimsical/re-frame-utils#inject
I have mixed feelings about if this is something re-frame
rs would consider an anti-pattern though. It has some oddities at least
For better of for worse, I’ve used event handler subs injections with this lib though. I just try to keep my usages to a minimum
This is discussed more in https://github.com/Day8/re-frame/issues/255 if you are interested
yeah i mean in general it’s a valid requirement. but it can kind of mess with the ideal flow, and in a degenerate case, create like an infinite event loop
I end up needing to be sure that multiple handlers do things like “clear derived data” that others may have made
On the event handling side, I feel it is just ad hoc and brittle. I may just be Doing It Wrong ™
I may not be able to accurately explain the situation either hah. I relate to what you are trying to do and just am reminded about some struggles I’ve had from it.
and basically if the key im updating is in a function apply that function to the db
@mikerod To make sure that you always, as you put it, "clear derived data" when some of the events might have invalidated some data, you can split [some of] your events in two parts. One part is the user intent, and the other is the one that changes actual DB values. In this case, all changes to :field1
and :field2
will be made by two event handlers. After this split, you can make them both have the same interceptor that re-calculates and stores value for :field3
.
@p-himik interesting. So you are describing using an intercepter to create this derived data into the db “automatically” for event handlers that include it?
I’ve not really explored much interesting usages of intercepters. If I understand you correct, that is an intriguing thought
the problem for me is that i need that behavior to be somewhat dynamic. I can’t ‘hardcode’ the interceptors, etc
@eoinmonty Can you give a small example? I don't quite understand what you mean by "somewhat dynamic". @fabrao Nothing should prevent you from doing that, unless you change re-frame-utils and somehow introduce a circular dependency.