More work on subscriptions docs

This commit is contained in:
Mike Thompson 2016-12-18 23:27:08 +11:00
parent e8620221ea
commit f8ea6a3282
2 changed files with 9 additions and 7 deletions

View File

@ -1,10 +1,12 @@
## Subscription Infographics
Before studying this infographic, be sure you have read the
annotated subscription code [in the todomvc example](https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs).
<img src="/images/subscriptions.png?raw=true">
***
Previous: [Coeffects](Coeffects.md)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Up: [Index](README.md)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Next: [Effectful Handlers](EffectfulHandlers.md)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Next: [Basic App Structure](Basic-App-Structure.md) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

View File

@ -1,12 +1,12 @@
(ns todomvc.subs
(:require [re-frame.core :refer [reg-sub subscribe]]))
;; Using `reg-sub`, you can write subscription handlers without ever
;; using `reaction` directly.
;; This is how you would register a simple handler.
;; -------------------------------------------------------------------------------------
;; Layer 2 (see the infographic for meaning)
;;
(reg-sub
:showing
(fn [db _] ;; db is the value in app-db
(fn [db _] ;; db is the (map) 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.
;; so that `fn` is a pure function
@ -20,7 +20,7 @@
(reg-sub :sorted-todos sorted-todos)
;; -------------------------------------------------------------------------------------
;; Beyond Simple Handlers
;; Layer 3 (see the infographic for meaning)
;;
;; A subscription handler is a function which is re-run when its input signals
;; change. Each time it is rerun, it produces a new output (return value).