metosin / reagent-dev-tools

Development tool panel for Reagent
21 stars 2 forks source link

allow passing parameters to custom panels #6

Open ikitommi opened 2 years ago

ikitommi commented 2 years ago

currently the panel-functions are 0-arity. To write reusable panels, there should be a way to pass parameters to them. Few suggestions:

1) pass the start! options to panels

(defn permissions-view [{:keys [permissions]}]
  ...)

(dev-tools/start!
 {:state-atom re-frame.db/app-db
  :permissions #{:a :b}
  :panels-fn {:permissions {:label "Permissions" :fn permissions-view}}})

2) like 1, but just one key, e.g. :data

(dev-tools/start!
 {:state-atom re-frame.db/app-db
  :data {:permissions #{:a :b}}
  :panels-fn {:permissions {:label "Permissions" :fn permissions-view}}})

3) something else

Deraen commented 2 years ago

partial?

ikitommi commented 2 years ago

out of these, I would prefer 3, then 4, both 2 & 1 seem hacks to me.

1) partial

(dev-tools/start!
 {:state-atom re-frame.db/app-db
  :panels-fn {:permissions {:label "Permissions" :fn (partial permissions-view {:permissions #{:a :b}})}}})

2) reuse whole panel submap

(dev-tools/start!
 {:state-atom re-frame.db/app-db
  :panels-fn {:permissions (permissions-panel-info {:permissions #{:a :b}})}}})

3) support reagent syntax

(dev-tools/start!
 {:state-atom re-frame.db/app-db
  :panels-fn {:permissions {:label "Permissions" :fn [permission-view {:permissions #{:a :b}}]}}})

;; rename keys
(dev-tools/start!
 {:state-atom re-frame.db/app-db
  :panels {:permissions {:label "Permissions" :view [permission-view {:permissions #{:a :b}}]}}})

4) single options map

(dev-tools/start!
 {:state-atom re-frame.db/app-db
  :data {:permissions #{:a :b}}
  :panels-fn {:permissions {:label "Permissions" :fn permissions-view}}})
Deraen commented 2 years ago
  1. seems fine. Maybe keeping :fn as is, and adding :view.
Deraen commented 2 years ago

I wonder if I had some reason why the option is panels-fn now, and the value must a function...

Might be related to the preload namespace, where the options need to be declared on compiler options.