Removed possibly confusing usage of spec to parse function arguments in register-pure

This commit is contained in:
Stuart Mitchell 2016-07-20 17:42:56 +12:00
parent 8e211754a3
commit 25a197cdd9
2 changed files with 24 additions and 34 deletions

View File

@ -1,7 +1,7 @@
## 0.8.0 (2016.07.XX)
Deftly surfing buzzword waves is obviously crucial for any framework. Angular's terrifying faceplant
is a sobering reminder to us all - a rooster one day and a feather duster the next. With this release,
is a sobering reminder to us all - a rooster one day and a feather duster the next. With this release,
re-frame's already impressive buzzword muscles
bulge further with new walnuts like "effects", "coeffects", and "de-duplicated signal graph". I know, right?
@ -12,8 +12,8 @@ Headline
Joking aside, this is a substantial release which will fundamentally change how you use re-frame:
- re-frame subscriptions are now de-duplicated. As a result,
many Signal graphs will be more efficient. The new behaviour better
matches programmer intuitions about what "should" happen.
many Signal graphs will be more efficient. The new behaviour better
matches programmer intuitions about what "should" happen.
*Explanation*
@ -42,7 +42,7 @@ Joking aside, this is a substantial release which will fundamentally change how
which makes them easier to understand and test etc. Plus, as you'll see in the docs, there is some
gratuitous syntactic sugar.
The todomvc example is a tutorial on the subject:
The todomvc example is a tutorial on the subject:
https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs
- The API for the undo/redo features has been put into `re-frame.core`.
@ -52,14 +52,14 @@ Joking aside, this is a substantial release which will fundamentally change how
Plus, this release has [a couple of enhancements](https://github.com/Day8/re-frame/wiki/Undo-&-Redo#harvesting-and-re-instating)
over that which previously existed previously.
- there's now two kinds of event handlers: pure and effectful. XXX
For description see: https://github.com/Day8/re-frame/wiki/Effectful-Event-Handlers
For examples see:
- there's now two kinds of event handlers: pure and effectful. XXX
For description see: https://github.com/Day8/re-frame/wiki/Effectful-Event-Handlers
For examples see:
1. https://github.com/Day8/re-frame-http-fx
2. https://github.com/Day8/re-frame-forward-events-fx
3. https://github.com/Day8/re-frame-async-flow-fx
- taking advantage of the new effectful event handlers, there's now a new library
which makes it easy to XXXX
@ -98,17 +98,16 @@ Breaking:
Improvements:
- XXX (full-debug!)
- XXX middleware for spec checking of event vectors
- XXX remove use of spec in reg-sub
- Enhancement:
- Enhancement:
- Bug fix: `post-event-callbacks` were not called when `dispatch-sync` was called.
- added new API `re-frame.core/remove-post-event-callback`. See doc string.
- when an event-handler makes no change to `app-db`, the `debug` middleware now logs a
single line saying so, rather than a "group". Makes it slightly easier to grok
the absence of change.
- Standardised test namespaces: renamed to use -test suffix and moved to eliminate redundant /test folder
- Added cljs.test based tests via browser/html. These mimic original karma tests. NOTE: previous
lein aliases `once` and `auto` have been replaced by `test-once` , `test-auto` & `karma-once`
- Added cljs.test based tests via browser/html. These mimic original karma tests. NOTE: previous
lein aliases `once` and `auto` have been replaced by `test-once` , `test-auto` & `karma-once`
see [CONTRIBUTING.md](CONTRIBUTING.md)

View File

@ -1,6 +1,5 @@
(ns re-frame.subs
(:require
[cljs.spec :as s]
[reagent.ratom :as ratom :refer [make-reaction] :refer-macros [reaction]]
[re-frame.db :refer [app-db]]
[re-frame.loggers :refer [console]]
@ -92,12 +91,6 @@
;; -- Helper code for register-pure -------------------
(s/def ::register-pure-args (s/cat
:sub-name keyword?
:sub-fn (s/? fn?)
:arrow-args (s/* (s/cat :key #{:<-} :val vector?))
:f fn?))
(defn- fmap
"Returns a new version of 'm' in which f has been applied to each value.
(fmap inc {:a 4, :b 2}) => {:a 5, :b 3}"
@ -146,14 +139,17 @@
of cases where only a simple subscription is needed without any parameters
"
[& args]
(let [conform (s/conform ::register-pure-args args)
{:keys [sub-name
sub-fn
arrow-args
f]} conform
arrow-subs (->> arrow-args
(map :val))]
[sub-name & args]
(let [f (last args) ;; grab the last arg
middle-args (butlast args) ;; grab the middle args
maybe-func (first middle-args)
sub-fn (when (fn? maybe-func) maybe-func)
arrow-args (if (fn? maybe-func)
(rest middle-args)
middle-args)
arrow-subs (->> arrow-args
(partition 2)
(map last))]
(cond
sub-fn ;; first case the user provides a custom sub-fn
(register
@ -162,7 +158,7 @@
(let [subscriptions (sub-fn q-vec d-vec)] ;; this let needs to be outside the fn
(ratom/make-reaction
(fn [] (f (multi-deref subscriptions) q-vec d-vec))))))
arrow-args ;; the user uses the :<- sugar
(seq arrow-args) ;; the user uses the :<- sugar
(register
sub-name
(fn [db q-vec d-vec]
@ -176,9 +172,4 @@
(register ;; the simple case with no subs
sub-name
(fn [db q-vec d-vec]
(ratom/make-reaction (fn [] (f @db q-vec d-vec))))))))
#_(s/fdef register-pure
:args ::register-pure-args)
#_(s/instrument #'register-pure)
(ratom/make-reaction (fn [] (f @db q-vec d-vec)))))))())