Fork me on GitHub

hello! I have an effect to track analytics and its fn gets three params: event name, event data and some common data that depends on the updated db (with updated db I mean the new version of db the event handler computes) this is my current solution:

(reg-event-fx :my-event
  (fn [{:keys [db]} [_ param1]
    (let [new-db (build-new-db db param1)]
      {:db new-db
       :analytics ["name" {:a param1} (common-analytics-data new-db)]})))
I don’t like two things: • I always have to pass the same third param • The third param is computed using the new-db, so I don’t want that it’s possible to make the mistake of passing the old db Is there a way to do this in a more elegant way? for example, using an interceptor that gets the :analytics effect with only two params and adds the third one before the effect is executed


we have a working solution with an empty effect and an interceptor that looks in :after for that concrete effect key and does the actual tracking, with the two first params of the effect and adding by itself the common info, given that it has access to the updated db, but I don’t like that we need to declare an empty effect doing nothing


@UUKNATU4B the interceptor can add the effect


In fact the interceptor can could action the effect itself, and then not even need to add an effect to the list. .


how do you mean? I don’t think I follow. If the effect is not in the map of effects returned by the event handler, how does the interceptor know that some code must be run? (this is how our current solution, but we need to declare an empty effect and also add the effect to the effect map (because not all event handlers have analytics)