Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support subscribing to subscriptions #2

Closed
valerauko opened this issue Jun 5, 2023 · 7 comments · Fixed by #6
Closed

Support subscribing to subscriptions #2

valerauko opened this issue Jun 5, 2023 · 7 comments · Fixed by #6

Comments

@valerauko
Copy link
Contributor

re-frame supports multiple layers of subscriptions and it only recomputes what's necessary. cf https://day8.github.io/re-frame/subscriptions/#why-layer-2-extractors

How difficult do you think this could be to port to re-dash?

@wkok
Copy link
Collaborator

wkok commented Jun 5, 2023

Hello!

re-dash subscriptions internally uses ClojureDart Cells to watch for changes to a specific key in app-db, which similar to re-frame would only result in recomputing the view if the value subscribed to actually changed.

For example, given an app-db of

{:name1 "Jack"
 :name2 "Jill"}

and the view subscribes to both names individually:

(m/Column
   .children
   [(f/widget
      :watch [name1 (rd/subscribe [::model/get-name1])]
      (m/Text name1))
    (f/widget
      :watch [name2 (rd/subscribe [::model/get-name2])]
      (m/Text name2))])

then say only :name1 is later changed from anywhere, we can be sure that the widget tree for :name2 won't be recomputed

Is there something more that multi layer subscriptions gives that I may be missing?

@wkok
Copy link
Collaborator

wkok commented Jun 5, 2023

Ahh the link you shared refered to layer 2 extractors, but I think you're referring to layer 3 materialised view mentioned here
https://day8.github.io/re-frame/subscriptions/#the-four-layers

That requires some thinking, but yes, it would be nice to support

@valerauko
Copy link
Contributor Author

Sorry, I meant to link to the layer 3 materialised view part...

In re-frame these "input functions" subscribe to other subscriptions. Is such a thing possible with cljd cells?

@wkok
Copy link
Collaborator

wkok commented Jun 6, 2023

Yes, according to the ClojureDart cheatsheat cells can have other cells as their dependencies.

I'll experiment with it a bit in the next couple days

@wkok
Copy link
Collaborator

wkok commented Jun 6, 2023

Promising news, in the layer-3-materialised-view branch it works now where a subscription can subscribe to one other subscription (single signal) via the signals function

Not yet implemented is to support a vector or a map of signals, but at the moment this works:

  ;; Layer 2 - Extractor
  (rd/reg-sub
    ::get-count
    (fn [db _query-vec]
      (:current-count db 0)))


  ;; Layer 3 - Materialised View
  (rd/reg-sub
    ::get-count-description

    ;; signals function
    (fn [query-v]
      (rd/subscribe [::get-count query-v]))

    ;; computation function
    (fn [get-count _query-v]
      (str "The count is exactly " get-count)))

@valerauko
Copy link
Contributor Author

valerauko commented Jun 7, 2023

Awesome! If you'd rather, I can help from there and implement the rest of the feature?

@wkok
Copy link
Collaborator

wkok commented Jun 7, 2023

I've just pushed a commit to this branch that adds support for a vector or map of signals

@valerauko valerauko mentioned this issue Jun 9, 2023
11 tasks
@wkok wkok closed this as completed in #6 Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants