Move to using reg-sub (rather than register-sub-pure)

This commit is contained in:
Mike Thompson 2016-06-24 23:15:00 +10:00
parent cbef1ec268
commit 8747d2b14a
2 changed files with 13 additions and 15 deletions

View File

@ -1,10 +1,10 @@
(ns todomvc.subs
(:require [re-frame.core :refer [register-pure-sub subscribe]]))
(:require [re-frame.core :refer [reg-sub subscribe]]))
;; register-pure-sub allows us to write subscription handlers without ever
;; using `reaction` directly.
;; This is how you would register a simple handler.
(register-pure-sub
(reg-sub
:showing
(fn [db _] ;; db, is the value in app-db
(:showing db))) ;; I repeat: db is a value. Not a ratom. And this fn does not return a reaction, just a value.
@ -17,7 +17,7 @@
(defn sorted-todos
[db _]
(:todos db))
(register-pure-sub :sorted-todos sorted-todos)
(reg-sub :sorted-todos sorted-todos)
;; -------------------------------------------------------------------------------------
;; Beyond Simple Handlers
@ -47,7 +47,7 @@
;; In the two simple examples at the top, we only supplied the 2nd of these functions.
;; But now we are dealing with intermediate nodes, we'll need to provide both fns.
;;
(register-pure-sub
(reg-sub
:todos
;; This function returns the input signals.
@ -77,7 +77,7 @@
;; As a result note:
;; - the first function (which returns the signals, returns a 2-vector)
;; - the second function (which is the computation, destructures this 2-vector as its first parameter)
(register-pure-sub
(reg-sub
:visible-todos
(fn [query-v _] ;; returns a vector of two signals.
[(subscribe [:todos])
@ -115,7 +115,7 @@
;; register-pure-sub provides some macro sugar so you can nominate a very minimal
;; vector of input signals. The 1st function is not needed.
;; Here is the example above rewritten using the sugar.
#_(register-pure-sub
#_(reg-sub
:visible-todos
:<- [:todos]
:<- [:showing]
@ -127,19 +127,19 @@
(filter filter-fn todos))))
(register-pure-sub
(reg-sub
:all-complete?
:<- [:todos]
(fn [todos _]
(seq todos)))
(register-pure-sub
(reg-sub
:completed-count
:<- [:todos]
(fn [todos _]
(count (filter :done todos))))
(register-pure-sub
(reg-sub
:footer-counts ;; XXXX different from original. Now does not return showing
:<- [:todos]
:<- [:completed-count]

View File

@ -9,13 +9,12 @@
;; -- API -------
;; See also macros in clj file
(def dispatch router/dispatch)
(def dispatch-sync router/dispatch-sync)
(def register-sub subs/register)
(def register-pure-sub subs/register-pure)
(def reg-sub subs/register-pure)
(def clear-sub-handlers! subs/clear-handlers!)
(def subscribe subs/subscribe)
@ -33,17 +32,16 @@
;; -- Undo API -----
;; For an explanation of the undo/redo capabilities:
;; https://github.com/Day8/re-frame/wiki/Undo-&-Redo
;; Docs on undo/redo: https://github.com/Day8/re-frame/wiki/Undo-&-Redo
(def undoable undo/undoable)
(def undo-config! undo/undo-config!)
;; -- Logging -----
;; re-frame uses the logging functions: warn, log, error, group and groupEnd
;; Internally, re-frame uses the logging functions: warn, log, error, group and groupEnd
;; By default, these functions map directly to the js/console implementations,
;; but you can override with your own (set or subset).
;; but you can override with your own fns (set or subset).
;; Example Usage:
;; (defn my-warn-fn [& args] (post-it-somewhere (apply str args)))
;; (re-frame.core/set-loggers! {:warn my-warn-fn})