Commit Graph

11 Commits

Author SHA1 Message Date
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
Daniel Compton 409b001e26 Clean up spelling, tense, and docstrings 2015-05-26 09:37:10 +12:00
mike-thompson-day8 7ebfc2a9ba Start using "error" instead of "warn" for bad things 2015-05-02 10:48:31 +10:00
mike-thompson-day8 7d85dbca48 Remove unneeded require 2015-04-27 07:39:17 +10:00
mike-thompson-day8 c1fe51ddfd Partially fix #43 by adding ability to clear both kinds of handlers. 2015-04-25 09:50:46 +10:00
mike-thompson-day8 72b605340e Bump various for a v0.3.2 release 2015-04-22 00:18:31 +10:00
mike-thompson-day8 5602bffc6b WIP on subs 2015-04-17 23:51:29 +10:00
mike-thompson-day8 a7f5aca490 improve comment 2015-03-05 10:40:21 +11:00
mike-thompson-day8 9f233f07b7 Change warning 2015-02-25 08:26:47 +11:00
mike-thompson-day8 a9c8d76e1e Tweaks mostly. 2015-02-22 22:28:40 +11:00
mike-thompson-day8 8654613087 Split handlers from subscriptions 2014-12-15 22:56:32 +11:00