crisptrutski / matchbox

Firebase client for Clojure(Script)
Eclipse Public License 1.0
160 stars 20 forks source link

Reference counting #52

Open theronic opened 8 years ago

theronic commented 8 years ago

;) 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. :+1: :8ball:

crisptrutski commented 8 years ago

Pull requests welcome :stuck_out_tongue_closed_eyes:

crisptrutski commented 8 years ago

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

crisptrutski commented 8 years ago

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?