Whats wrong with (_re-matches_ #"\S{1,}\/\S{1,}" "users/232")
You don't need to escape /
(re-matches #"\S{1,}/\S{1,}" "users/232")
The reason why you normally need to escape it is that you write it in the form s/.../.../
where everything is a string. You are not using this form in Clojure.
on <http://regexr.com|regexr.com>
same regex is working
I'd like to subscribe to db changes on certain keys and trigger events if the resulting values meet some conditions. there are many different events that could change those db entries, and I don't want to have to add interceptors for all those, so I thought just subscribing for the output db state would be more elegant
I'd like to do that outside of any reagent component, since this logic doesn't belong in any particular component
do I need to explicitly watch for changes in the atom returned by re-frame.core/subscribe
?
or is there a more idiomatic way?
@euccastro
Various options:
First, you could add create an interceptor which detects the change and actions it (dispatches an event?) using a global interceptor ... written like the standard on-change
one
Second you can do it with subscriptions which isn't very idiomatic, but it isn't exactly hard either. I'll rustle up some code if you are keen .
thanks @mikethompson!! I'll chew on those options for a bit..
just wanted to make sure I wasn't missing some established way to do that kind of thing
The docstring for on-changes
is here:
https://github.com/day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc#L206-L227
And the implementation of on-changes
is here:
https://github.com/day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc#L206-L227
And you can see use of global interceptors here:
https://day8.github.io/re-frame/FAQs/GlobalInterceptors/#answer-v100-onwards
Regarding the subscriptions approach ... It is a while since I've had to write this kind of code ... so I fear I might be be doing it wrongly, but here's the idea ...
(defonce some-name
(reagent/reaction
(do
@subscribe([:a-sub-to-watch-for-changes])
(dispatch [:the-event])))
@euccastro ^^
thank you very much! I think a globally registered on-changes
interceptor might work for my use case, since I actually want to effect derived db changes
Also this looks nice
https://github.com/den1k/re-frame-utils/blob/master/src/vimsical/re_frame/fx/track.cljc