Commit Graph

18 Commits

Author SHA1 Message Date
Stuart Mitchell f4fb65037e Subscriptions sugar - changed to provide a singleton 2016-06-22 15:41:22 +12:00
Mike Thompson af2fd0b21f Merge branch 'develop' of https://github.com/Day8/re-frame into develop
Conflicts:
	src/re_frame/subs.cljs
2016-06-14 21:14:49 +10:00
Mike Thompson 4741cd73d3 Better naming and comments. 2016-06-14 21:10:56 +10:00
Stuart Mitchell 5a4d78ecc8 register-pure-sub: moved into correct namespace 2016-06-14 14:52:37 +12:00
Mike Thompson 3d4e8cde8f Introduce de-duplicated subscriptions. 2016-05-29 23:23:17 +10:00
Daniel Compton 3e8f1e1dfa Log warning when non reactive parameters are passed to dynamic subscriptions
Closes #115
2015-10-16 14:47:15 +13:00
Daniel Compton 518ff995dc Remove extra level of indirection when creating dynamic subscription
Instead of creating a RAtom and resetting into it on a seperate side
chain of our dependency graph, we can instead return a reaction which is
the result of @@sub, achieving the same goals but with less code and
complexity.
2015-10-16 14:47:15 +13:00
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