Created
December 18, 2016 02:50
-
-
Save mike-thompson-day8/abfff0ba61843c2d5884dbff2fed7ea4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
View functions with a subscription are not pure. They are obtaining an "input" from a non argument source. | |
From a practical point view, I haven't been motivated to solve this problem - non-local reasoning is not a problem, and neither is testing because subscribe is easy to stub out, so it feels like you are dealing with a pure function - HOWEVER from a theoretical point of view, this is certainly a "pebble in the shoe". In due course, I'd like it fixed. | |
Here's a quick sketch of approximated how (not all issues resolved): | |
1. create a new `reg-view` function thru which all views are associated with an `id`. Make this registration much like `reg-sub` in the way that you can nominate N signal inputs via a signals function. | |
2. change Reagent so that the first element of vector can be an `id` previously registered by `reg-view`. So, instead of `:div`, you could use `:something/panelX` | |
Would be used like this (notice how similar this is to reg-sub): | |
``` | |
(re-frame.core/reg-view ;; <--- new | |
:a-view-id ;; an id for this view | |
;; input signals function | |
;; what it returns will become the first param passed to the computation function | |
(fn [item-id another] ;; given props | |
(subscribe [:item item-id])) | |
;; computation function which returns hiccup | |
(fn [item item-id another] ;; given props BUT with values from subscription prepended | |
[:div (:name item)])) | |
``` | |
The computation becomes pure. The "subscribed to' values are put in the first argument (same pattern as is currently used with `reg-sub`). | |
Later, when you wanted to use this view: | |
`[:a-view-id 12 "hello"]` | |
Reagent would look up the view id `a-view-id` and use the associated | |
Open Questions: | |
- how to do Form-2 views or Form-3? This could be a stumbling block | |
Implementation: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment