Fork me on GitHub

So I just found out my re-frame subscriptions are quite expensive, so I thought the best way to fix it would be to use Layer 2 and layer 3 subscriptions. An example of my current code non-optimized code:

  (fn [{:keys [one two three] :as app-db} _]
    (expensive-stuff one two three)))


For this I need 3 Layer2 subscriptions, one for each attribute. What I don't like is having to define names for each sub, so I ended up doing this

  (fn [app-db [_ k]]
    (get app-db k)))

  :<- [:get-db-key :one]
  :<- [:get-db-key :two]
  :<- [:get-db-key :three]
  (fn [[one two three] _]
    (expensive-stuff one two three)))
Is this ok? This could help 'anonymize' the 3 subscriptions I needed. Is there any way to define anonymous subscriptions that I could use in my Layer 3 subs?


I'd say it's alright as long as you don't use :get-db-key in view functions, only in other subs. Personally, I would even name it ::-get-db-key to indicate that it's "private". Also, to avoid multiple signals, you can write something like :get-db-keys that returns a map of multiple keys at once. Depends on whether it's a useful pattern in other places.


I like the private idea! as I'll probably forget that :get-db-key is only meant as a layer 2 sub :thinking_face:


thanks for the suggestions!

👍 1