Initial fx code now in. But it remains largely untested.

This commit is contained in:
Mike Thompson 2016-07-14 16:41:54 +10:00
parent a1314eb6c3
commit 2c9d140c22
4 changed files with 61 additions and 59 deletions

View File

@ -2,14 +2,14 @@
Staying on the leading edge of new buzzwords is obviously critical for any framework. Angular's terrifying faceplant
is a sobering reminder to us all. With this release, re-frame's already impressive buzzword muscles
bulge further with new walnuts like "effects", "coeffects", and "de-duplicated signal graph". Yeah, I know, right?
bulge further with new walnuts like "effects", "coeffects", and "de-duplicated signal graph". I know, right?
Some may even find these new features useful.
Headline:
- 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*
@ -38,7 +38,7 @@ Headline:
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`.
@ -48,7 +48,7 @@ Headline:
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
- 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
- taking advantage of the new effectful event handlers, there's now a new library
@ -86,10 +86,10 @@ Breaking:
(defn my-logger [& args] (do-something-with (apply str args))
```
Improvements
- XXX (full-debug!)
- XXX middleware for spec checking of event vectors
- XXX todomvc changed to use spec, instead of Schema
Improvements:
- XXX (full-debug!)
- XXX middleware for spec checking of event vectors
- XXX todomvc changed to use spec, instead of Schema
- 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.
@ -97,16 +97,10 @@ Improvements
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` see [CONTRIBUTING.md](CONTRIBUTING.md)
- 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)
####Other:####
- changed dev deps/plugins
<pre>
binaryage/devtools "0.7.2"
lein-npm "0.6.2"
lein-figwheel "0.5.4-7"
lein-shell "0.5.0" (added)
</pre>
## 0.7.0 (2016-03-14)

View File

@ -1,41 +1,40 @@
# Contributing to re-frame
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
The following is a set of guidelines for contributing to re-frame which is hosted on [Github](https://github.com/Day8/re-frame).
These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request.
Thank you for taking the time to contribute!
## Support questions
**The Github issues for re-frame are for bug reports and feature requests. Support requests and usage questions should go to the [Clojure Slack channel](http://clojurians.net), the [ClojureScript mailing list](https://groups.google.com/forum/#!forum/clojurescript), or the [Reagent mailing list](https://groups.google.com/forum/#!forum/reagent-project).**
## Creating issues for bugs
Check if the issue has already been reported. If possible provide:
* Version of re-frame being used
* Minimal reproduction steps
## Creating issues for features
Use your best judgement on what is needed here.
The Github issues are for bug reports and feature requests only. Support requests and usage
questions should go to the re-frame [Clojure Slack channel](http://clojurians.net) or
the [ClojureScript mailing list](https://groups.google.com/forum/#!forum/clojurescript).
## Pull requests
**Create pull requests to the develop branch**, work will merged onto master when it is ready to be released.
**Create pull requests to the develop branch**, work will be merged onto master when it is ready to be released.
## Running the tests
## Running tests
#### Via Browser/HTML
To build the tests and run them in one step, just:
```sh
lein test-once # builds re-frame tests & opens browser on test/test.html
# or lein test-auto # then open a browser on test/test.html
# and refresh browser to rerun tests after each auto compile.
lein test-once # compiles & then opens test.html in the browser
```
You can also get auto compiles via:
```sh
lein test-auto
```
but you'll need to manually open `test/test.html` in a browser. And you'll also need to
manually reload this page after each auto compile.
#### Via Karma
To run the tests, you must have recent versions of node, npm, Leiningen, and a C++ compiler toolchain installed. If you're on Linux or Mac OS X then you will be fine, if you're on Windows then you need to install Visual Studio Community Edition, and the C++ compiler dependencies.
To run the tests, you must have recent versions of node, npm, Leiningen, and a C++ compiler
toolchain installed. If you're on Linux or Mac OS X then you will be fine,
if you're on Windows then you need to install Visual Studio Community Edition,
and the C++ compiler dependencies.
```sh
lein deps # runs lein-npm, installs Karma & other node dependencies. Only needed the first time.

View File

@ -52,7 +52,9 @@
(defn clear-handler!
[id]
(swap! dissoc id->fn id))
(if (lookup-handler id)
(swap! id->fn dissoc id)
(console :warn "re-frame: unable to clear event handler for " id ". Not defined.")))
(defn register-base

View File

@ -21,18 +21,20 @@
(defn clear-handler!
[effect-id]
(swap! id->handler-fn dissoc effect-id))
(if (lookup-handler effect-id)
(swap! id->handler-fn dissoc effect-id)
(console :warn "re-frame: unable to clear effect handler for " effect-id ". Not defined.")))
(defn register
"register a handler fn for an effect."
[event-id handler-fn]
(when (contains? @id->handler-fn event-id)
(console :warn "re-frame: overwriting an effects handler for: " event-id)) ;; allow it, but warn.
(swap! id->handler-fn assoc event-id handler-fn))
[effect-id handler-fn]
(when (lookup-handler effect-id)
(console :warn "re-frame: overwriting an effects handler for: " effect-id)) ;; allow it, but warn.
(swap! id->handler-fn assoc effect-id handler-fn))
;; -- Standard effets ---------------------------------------------------------
;; -- Standard Builtin Effects Handlers --------------------------------------
(defn dispatch-helper
[effect]
@ -52,10 +54,17 @@
(doseq [[ms events] effect]
(js/setTimeout #(dispatch-helper events) ms))))
;; Supply either a vector or a list of vectors. For example:
;;
;; {:dispatch [:event-id "param"] }
;;
;; {:dispatch (list [:do :all] [:three :of] [:these]) }
;;
(register
:dispatch
(fn [effect]
(dispatch-helper effect)))
(fn [val]
(dispatch-helper val)))
;;
@ -92,8 +101,8 @@
(register
:db
(fn [effect]
(reset! app-db effect)))
(fn [val]
(reset! app-db val)))
;; -- Middleware --------------------------------------------------------------
@ -110,11 +119,9 @@
[handler]
(fn fx-handler
[app-db event-vec]
(let [world {:db @app-db}
result (handler world event-vec)
effects (-> result (dissoc :db) keys)
handlers (map lookup-handler effects)
retult' (reduce #(%2 %1) result handlers)]
(if-let [db (:db result)]
(reset! app-db db)))))
(let [world {:db @app-db}]
(->> (handler world event-vec)
(map (fn [[key val]]
(if-let [effect-fn (lookup-handler key)]
(effect-fn val)
(console :error "re-frame: no effects handler defined for: " key ". Ignoring"))))))))