re-frame/src/re_frame
Daniel Compton 7e492930e3 Add dynamic subscriptions to re-frame
Dynamic subscriptions allow the user to specify subscriptions that
depend on Ratoms/Reactions and will be rerun when they change. Users
will subscribe with v and a vector of dynamic values. The dynamic values
are dereffed and passed to the handler-fn. Dynamic subscriptions need to
pass a fn which takes app-db, v, and the dereffed dynamic values.

Every time a dynamic value changes, handler-fn will be rerun. This is in
contrast to standard subscriptions where handler-fn will only be run
once, although the reaction that it produces will change over time.

A concrete example of the need for this is:
1. You want to subscribe to a query on a remote server which will return
a Reaction which changes in response to server changes.
2. You want this subscription to be able to be rerun when you change one
of the query parameters.

In the current system, all views need to be aware of the possibility of
changing parameters and provide them in their subscriptions.

Example usage code:

(register-sub
  :todo-dynamic
  (fn todo-dynamic [_ _ [active-list]]
    (let [q (q/get-query active-list)]
      q)))

(register-sub
  :todos
  (fn todos [db _]
    (let [active-list (subscribe [:active-list])
          todos       (subscribe [:todo-dynamic] [active-list])]
      (make-reaction (fn todo-vals [] (update @todos :result #(vals (:list %))))))))
2015-10-16 14:46:54 +13:00
..
core.cljs Improve comments around logging 2015-05-02 10:46:05 +10:00
db.cljs Clean up spelling, tense, and docstrings 2015-05-26 09:37:10 +12:00
handlers.cljs fixes bug introduced by 8af8c6840f 2015-07-17 11:51:34 +12:00
middleware.cljs Merge pull request #100 from thenonameguy/patch-2 2015-09-12 20:27:35 +12:00
router.cljs Improve comments on router. 2015-05-08 15:49:48 +10:00
subs.cljs Add dynamic subscriptions to re-frame 2015-10-16 14:46:54 +13:00
undo.cljs Clean up spelling, tense, and docstrings 2015-05-26 09:37:10 +12:00
utils.cljs fixed issue with log groupings 2015-07-17 14:16:56 +12:00