mirror of
https://github.com/status-im/re-frame.git
synced 2025-02-22 14:58:12 +00:00
Move to using reg-sub (rather than register-sub-pure)
This commit is contained in:
parent
cbef1ec268
commit
8747d2b14a
@ -1,10 +1,10 @@
|
|||||||
(ns todomvc.subs
|
(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
|
;; register-pure-sub allows us to write subscription handlers without ever
|
||||||
;; using `reaction` directly.
|
;; using `reaction` directly.
|
||||||
;; This is how you would register a simple handler.
|
;; This is how you would register a simple handler.
|
||||||
(register-pure-sub
|
(reg-sub
|
||||||
:showing
|
:showing
|
||||||
(fn [db _] ;; db, is the value in app-db
|
(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.
|
(: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
|
(defn sorted-todos
|
||||||
[db _]
|
[db _]
|
||||||
(:todos db))
|
(:todos db))
|
||||||
(register-pure-sub :sorted-todos sorted-todos)
|
(reg-sub :sorted-todos sorted-todos)
|
||||||
|
|
||||||
;; -------------------------------------------------------------------------------------
|
;; -------------------------------------------------------------------------------------
|
||||||
;; Beyond Simple Handlers
|
;; Beyond Simple Handlers
|
||||||
@ -47,7 +47,7 @@
|
|||||||
;; In the two simple examples at the top, we only supplied the 2nd of these functions.
|
;; 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.
|
;; But now we are dealing with intermediate nodes, we'll need to provide both fns.
|
||||||
;;
|
;;
|
||||||
(register-pure-sub
|
(reg-sub
|
||||||
:todos
|
:todos
|
||||||
|
|
||||||
;; This function returns the input signals.
|
;; This function returns the input signals.
|
||||||
@ -77,7 +77,7 @@
|
|||||||
;; As a result note:
|
;; As a result note:
|
||||||
;; - the first function (which returns the signals, returns a 2-vector)
|
;; - 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)
|
;; - the second function (which is the computation, destructures this 2-vector as its first parameter)
|
||||||
(register-pure-sub
|
(reg-sub
|
||||||
:visible-todos
|
:visible-todos
|
||||||
(fn [query-v _] ;; returns a vector of two signals.
|
(fn [query-v _] ;; returns a vector of two signals.
|
||||||
[(subscribe [:todos])
|
[(subscribe [:todos])
|
||||||
@ -115,7 +115,7 @@
|
|||||||
;; register-pure-sub provides some macro sugar so you can nominate a very minimal
|
;; register-pure-sub provides some macro sugar so you can nominate a very minimal
|
||||||
;; vector of input signals. The 1st function is not needed.
|
;; vector of input signals. The 1st function is not needed.
|
||||||
;; Here is the example above rewritten using the sugar.
|
;; Here is the example above rewritten using the sugar.
|
||||||
#_(register-pure-sub
|
#_(reg-sub
|
||||||
:visible-todos
|
:visible-todos
|
||||||
:<- [:todos]
|
:<- [:todos]
|
||||||
:<- [:showing]
|
:<- [:showing]
|
||||||
@ -127,19 +127,19 @@
|
|||||||
(filter filter-fn todos))))
|
(filter filter-fn todos))))
|
||||||
|
|
||||||
|
|
||||||
(register-pure-sub
|
(reg-sub
|
||||||
:all-complete?
|
:all-complete?
|
||||||
:<- [:todos]
|
:<- [:todos]
|
||||||
(fn [todos _]
|
(fn [todos _]
|
||||||
(seq todos)))
|
(seq todos)))
|
||||||
|
|
||||||
(register-pure-sub
|
(reg-sub
|
||||||
:completed-count
|
:completed-count
|
||||||
:<- [:todos]
|
:<- [:todos]
|
||||||
(fn [todos _]
|
(fn [todos _]
|
||||||
(count (filter :done todos))))
|
(count (filter :done todos))))
|
||||||
|
|
||||||
(register-pure-sub
|
(reg-sub
|
||||||
:footer-counts ;; XXXX different from original. Now does not return showing
|
:footer-counts ;; XXXX different from original. Now does not return showing
|
||||||
:<- [:todos]
|
:<- [:todos]
|
||||||
:<- [:completed-count]
|
:<- [:completed-count]
|
||||||
|
@ -9,13 +9,12 @@
|
|||||||
|
|
||||||
|
|
||||||
;; -- API -------
|
;; -- API -------
|
||||||
;; See also macros in clj file
|
|
||||||
|
|
||||||
(def dispatch router/dispatch)
|
(def dispatch router/dispatch)
|
||||||
(def dispatch-sync router/dispatch-sync)
|
(def dispatch-sync router/dispatch-sync)
|
||||||
|
|
||||||
(def register-sub subs/register)
|
(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 clear-sub-handlers! subs/clear-handlers!)
|
||||||
(def subscribe subs/subscribe)
|
(def subscribe subs/subscribe)
|
||||||
|
|
||||||
@ -33,17 +32,16 @@
|
|||||||
|
|
||||||
|
|
||||||
;; -- Undo API -----
|
;; -- Undo API -----
|
||||||
;; For an explanation of the undo/redo capabilities:
|
;; Docs on undo/redo: https://github.com/Day8/re-frame/wiki/Undo-&-Redo
|
||||||
;; https://github.com/Day8/re-frame/wiki/Undo-&-Redo
|
|
||||||
|
|
||||||
(def undoable undo/undoable)
|
(def undoable undo/undoable)
|
||||||
(def undo-config! undo/undo-config!)
|
(def undo-config! undo/undo-config!)
|
||||||
|
|
||||||
|
|
||||||
;; -- Logging -----
|
;; -- 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,
|
;; 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:
|
;; Example Usage:
|
||||||
;; (defn my-warn-fn [& args] (post-it-somewhere (apply str args)))
|
;; (defn my-warn-fn [& args] (post-it-somewhere (apply str args)))
|
||||||
;; (re-frame.core/set-loggers! {:warn my-warn-fn})
|
;; (re-frame.core/set-loggers! {:warn my-warn-fn})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user