Fork me on GitHub
#re-frame
<
2016-01-19
>
mikethompson02:01:22

--------------- Dear all, consider using Dirac https://github.com/binaryage/dirac ----------------

hugobessaa13:01:09

I'm looking for a way to dispatch events when certain parts of the state changes

hugobessaa13:01:34

Like: I want to :fetch-search when :filters change

hugobessaa13:01:42

Would this be a bad idea?

hugobessaa13:01:12

I'm writing too much dispatches that dispatch to :fetch-search

mbertheau19:01:24

@hugobessaa: :fetch-search doesn't sound like an event. It sounds like that should be a normal function that's called in event handlers that change :filters.

mbertheau19:01:56

I understand your concern about preventing repitition and wanting to hook into "when :filters change. I believe that according to the idea and intention of re-frame there is no such hook and you should organize your events in a way that it doesn't feel like duplication when you call fetch-search in a lot of places: You're already setting :filters in a number of places (afaiu), instead in all these places you could have a function (fn set-filters [db new-filters] (do (fetch-search new-filters) (assoc db :filters new-filters))) or similar.

hugobessaa19:01:01

@mbertheau: thanks for your feedback! It really does look like a function

mikethompson19:01:28

@hugobessaa: yep, I agree with @mbertheau. Having said that, the on-change middleware might be useful, maybe https://github.com/Day8/re-frame/blob/master/src/re_frame/middleware.cljs#L197-L235