Merge branch 'develop' of https://github.com/Day8/re-frame into develop

This commit is contained in:
Mike Thompson 2016-12-09 10:34:17 +11:00
commit 9452f7812c
11 changed files with 57 additions and 43 deletions

View File

@ -6,6 +6,7 @@
<ClojureCodeStyleSettings>{
:cljs.core/with-redefs 1
:cursive.formatting/align-binding-forms true
:cursive.formatting/comment-align-column 0
:re-frame.trace/register-trace-cb :only-indent
:re-frame.trace/with-trace 1
}</ClojureCodeStyleSettings>
@ -15,6 +16,5 @@
</value>
</option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (2)" />
</component>
</project>

View File

@ -12,7 +12,6 @@
#### Improvements
- [#200](https://github.com/Day8/re-frame/pull/200) Remove trailing spaces from console logging
- [#248](https://github.com/Day8/re-frame/pull/248) Provide after interceptor with `db` coeffect, if no `db` effect was produced.
- Add `re-frame.loggers/get-loggers` function to well, you know.
- Added `clear-subscription-cache!` function. This should be used when hot reloading code to ensure that any bad subscriptions that cause rendering exceptions are removed. See [reagent-project/reagent#272](https://github.com/reagent-project/reagent/issues/272) for more details.
- Added experimental tracing features. These are subject to change and remain undocumented at the moment. By default they are disabled, and will be completely compiled out by advanced optimisations. To enable them, set a [`:closure-defines`](https://www.martinklepsch.org/posts/parameterizing-clojurescript-builds.html) key to `{"re_frame.trace.trace_enabled_QMARK_" true}`
@ -22,6 +21,8 @@
- [#259](https://github.com/Day8/re-frame/pull/259) Fix a bug where registering a subscription would create and close over dependent subscriptions, meaning that they would never be garbage collected, and doing more work than necessary.
- Fix a bug where subscribing to a subscription that didn't exist would throw an exception, instead of returning nil.
- [#248](https://github.com/Day8/re-frame/pull/248) Provide after interceptor with `db` coeffect, if no `db` effect was produced.
- [#278](https://github.com/Day8/re-frame/issues/278) Provide enrich interceptor with `db` coeffect, if no `db` effect was produced.
## 0.8.0 (2016.08.19)

View File

@ -22,7 +22,7 @@ y'know. Pretty good.
Perhaps:
1. You want to develop an [SPA] in ClojureScript, and you are looking for a framework
1. You want to develop an [SPA] in ClojureScript, and you are looking for a framework.
2. You believe Facebook did something magnificent when it created React, and
you are curious about the further implications. Is the combination of
`reactive programming`, `functional programming` and `immutable data` going to

View File

@ -108,17 +108,17 @@ For these applications, re-frame's `app-db` is mostly a local caching
point, and being able to do undo/redo its state is meaningless because the authoritative
source of data is elsewhere.
5. The ability to genuinely model control via FSMs (discussed later)
5. The ability to genuinely model control via FSMs (discussed later).
6. The ability to do time travel debugging, even in a production setting. More soon.
### Get You A Leveragable Schema
You, really do need a schema for `app-db`. Yes, it is optional, and I breezed past this
You really do need a schema for `app-db`. Yes, it is optional, and I breezed past this
earlier, but now I'm thumping the table and my face is red with intensity. You need one.
The todomvc example (in this repo) shows how to check `app-db` against your schema
The [todomvc example](https://github.com/Day8/re-frame/tree/master/examples/todomvc) (in this repo) shows how to check `app-db` against your schema
after every single event has been processed.
This is good: <br>

View File

@ -48,15 +48,17 @@ This app:
- provides a text input field into which you can type a hex colour code,
like "#CCC", for the time display
XXX screenshot
![Example App image](../images/example_app.png)
To run the code:
A. Install Java 8 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
B. Install leiningen (http://leiningen.org/#install)
* Install Java 8 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
* Install leiningen (http://leiningen.org/#install)
1. git clone https://github.com/Day8/re-frame.git
2. cd re-frame/examples/simple
3. lein do clean, figwheel
Then:
1. `git clone https://github.com/Day8/re-frame.git`
2. `cd re-frame/examples/simple`
3. `lein do clean, figwheel`
4. open http://localhost:3449/example.html
@ -472,7 +474,7 @@ It has two tasks:
```clj
(defn ^:export run
[]
(dispatch-sync [:initialize]) ;; puts a value into application state
(rf/dispatch-sync [:initialize]) ;; puts a value into application state
(reagent/render [ui] ;; mount the application's ui into '<div id="app" />'
(js/document.getElementById "app")))
```

View File

@ -1,7 +0,0 @@
(ns simpleexample.dev
(:require [simpleexample.core :as example]
[figwheel.client :as fw]))
(fw/start {:on-jsload example/run
:websocket-url "ws://localhost:3449/figwheel-ws"})

View File

@ -10,8 +10,8 @@
:hooks [leiningen.cljsbuild]
:profiles {:dev {:cljsbuild
{:builds {:client {:source-paths ["devsrc"]
:compiler {:main "simpleexample.dev"
{:builds {:client {:figwheel {:on-jsload "simple.core/run"}
:compiler {:main "simple.core"
:asset-path "js"
:optimizations :none
:source-map true

View File

@ -39,13 +39,10 @@
;; -- Domino 4 - Query -------------------------------------------------------
(rf/reg-sub
:time-str
:time
(fn [db _] ;; db is current app state. 2nd usused param is query vector
(-> db
:time
.toTimeString
(clojure.string/split " ")
first)))
:time)))
(rf/reg-sub
:time-color
@ -58,15 +55,18 @@
(defn clock
[]
[:div.example-clock
{:style {:color (rf/listen [:time-color])}}
(rf/listen [:time-str])]) ;; XXX listen
{:style {:color @(rf/subscribe [:time-color])}}
(-> @(rf/subscribe [:time])
.toTimeString
(clojure.string/split " ")
first)])
(defn color-input
[]
[:div.color-input
"Time color: "
[:input {:type "text"
:value (rf/listen [:time-color])
:value @(rf/subscribe [:time-color])
:on-change #(rf/dispatch [:time-color-change (-> % .-target .-value)])}]]) ;; <---
(defn ui
@ -80,7 +80,7 @@
(defn ^:export run
[]
(dispatch-sync [:initialize]) ;; puts a value into application state
(rf/dispatch-sync [:initialize]) ;; puts a value into application state
(reagent/render [ui] ;; mount the application's ui into '<div id="app" />'
(js/document.getElementById "app")))

BIN
images/example_app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -208,7 +208,9 @@
:after (fn enrich-after
[context]
(let [event (get-coeffect context :event)
db (get-effect context :db)]
db (or (get-effect context :db)
;; If no db effect is returned, we provide the original coeffect.
(get-coeffect context :db))]
(->> (f db event)
(assoc-effect context :db))))))

View File

@ -1,8 +1,8 @@
(ns re-frame.interceptor-test
(:require [cljs.test :refer-macros [is deftest]]
(:require [cljs.test :refer-macros [is deftest testing]]
[reagent.ratom :refer [atom]]
[re-frame.interceptor :refer [context get-coeffect assoc-effect assoc-coeffect get-effect]]
[re-frame.std-interceptors :refer [trim-v path on-changes after
[re-frame.std-interceptors :refer [debug trim-v path enrich after on-changes
db-handler->interceptor fx-handler->interceptor]]
[re-frame.interceptor :as interceptor]))
@ -48,13 +48,22 @@
((:after p))
(get-effect :db))))
;; test #2 - set dbto nil
;; test #2 - set db to nil
(is (= {:1 {:2 nil}}
(-> b4
(assoc-effect :db nil) ;; <-- db becomes nil
((:after p))
(get-effect :db)))))))
(deftest path-with-no-db-returned
(let [path-interceptor (path :a)]
(-> (context [] [path-interceptor] {:a 1})
(interceptor/invoke-interceptors :before)
interceptor/change-direction
(interceptor/invoke-interceptors :after)
(get-effect :db)
(nil?) ;; We don't expect an effect to be added.
(is))))
(deftest test-db-handler-interceptor
(let [event [:a :b]
@ -118,11 +127,18 @@
(deftest test-after
(let [after-db-val (atom nil)]
(-> (context [:a :b]
[(after (fn [db] (reset! after-db-val db)))]
{:a 1})
(interceptor/invoke-interceptors :before)
interceptor/change-direction
(interceptor/invoke-interceptors :after))
(is (= @after-db-val {:a 1}))))
(testing "when no db effect is returned"
(let [after-db-val (atom nil)]
(-> (context [:a :b]
[(after (fn [db] (reset! after-db-val db)))]
{:a 1})
(interceptor/invoke-interceptors :before)
interceptor/change-direction
(interceptor/invoke-interceptors :after))
(is (= @after-db-val {:a 1})))))
(deftest test-enrich
(testing "when no db effect is returned"
(let [ctx (context [] [] {:a 1})]
(is (= ::not-found (get-effect ctx :db ::not-found)))
(-> ctx (:after (enrich (fn [db] (is (= db {:a 1})))))))))