crisptrutski/matchbox

Reference counting

Opened this issue · 3 comments

;) When will we see some reference counting for subscribe/unsubcribe, or is this project just languishing under a full-time employed closed source owner??

I want to do this in Reagent:

(defn user-list-component []
  (let [users (mr/subscribe root [:users])]
    (fn []
      (for [u @users]
        [:span (:username u)]))))

Thinking just going to fork and rewrite in Scala.

Jesus, Chris. Get on it. 👍 🎱

Pull requests welcome 😝

To clarify what's being asked for - reuse of repeated listeners and removal of stale ones, to deliver zero-fuss re-frame subscriptions

So here's how I understand the degree to which we could take this:

  1. Interface which caches (r)atoms bound to refs.
  2. Interface to track "disposal" of subscriptions, and kill atom cache when 0 users
  3. Some kind of sugar to use (1) and (2) with lifecycle hooks in Reagent components
  4. Reuse existing (r)atoms that include given ref (ie. users andusers/0) via lens/cursor into the larger one.
  5. Prune "nested" subscriptions when "parent" subscriptions are added.
  6. Prune "parent" subscriptions when only lense subscriptions remain (ie. if watching users, then watching users/0), and reinstate the nested subscriptions.

Sounds like you just want (1)-(3)?

Not sure if (5) and (6) are even good ideas (can construct cases where they hurt more than help).

Would this still be a big win for you?