datodev / dato

Experiment in distilling apps to their essence
Eclipse Public License 1.0
168 stars 8 forks source link

Expose component parameters for static inspection/tooling/editing #9

Open sgrove opened 9 years ago

sgrove commented 9 years ago

Similar to Sul or Om/next. Just a rough sketch of what it might look like:

(defn my-com [data owner opts]
 (reify
   dato/IParams
   (params [_]
     {:tasks {:qes-by :task/title}
      :me {:qe-by :user/me? true}
      ;; Bit tricky w/ dep graph, something like prismatic fnk might enable this
      :local-session {:qe-by :session/user-id my-id}
      :filtered-task-ids {:q '[:find ?eid :in $ ?title-filter :where [?eid :task/title (re-match ?title-filter)]
      :current-company {:entity company-eid}
      :cases {:entities [case-eids]})
   dato/IRender
   (render [_]
     (let [data (dato/com-data owner)]
       ....))
  1. The inputs required to instantiate my-com would be {:company-eid ... :title-filter #"..." :case-eids [...] :my-id ...} (and the current db at render time),
  2. the value of data in render would have the same structure as specified in IParams

Other completely dynamic queries could be done in the render method if necessary, but whereas with the above format we can take care of (however inefficiently) automatically updating the component, it would the be up to the developer to make sure that listeners were added/removed on IWillMount and IWillUnmount for said dynamic queries.