mirror of https://github.com/status-im/reagent.git
Implement #439, make RAtom print output readable
This commit is contained in:
parent
68531569c0
commit
4526f4d1f9
|
@ -6,6 +6,11 @@
|
|||
defined `:class` ([#479](https://github.com/reagent-project/reagent/pull/479))
|
||||
- Fix using `:className` property together with keyword class shortcut ([#433](https://github.com/reagent-project/reagent/issues/433))
|
||||
- Fix incorrect missing React key warnings with `:>` ([#399](https://github.com/reagent-project/reagent/issues/399))
|
||||
- Change RAtom (all types) print format to be readable using ClojureScript reader,
|
||||
similar to normal Atom ([#439](https://github.com/reagent-project/reagent/issues/439))
|
||||
- Old print output: `#<Atom: 0>`
|
||||
- New print output: `#object[clojure.ratom.RAtom {:val 0}]`
|
||||
- Still not readable by default, requires custom reader for `object` tag.
|
||||
|
||||
## 0.10.0 (2020-03-06)
|
||||
|
||||
|
|
|
@ -102,10 +102,10 @@
|
|||
(f k this old new))
|
||||
(recur (+ 2 i))))))
|
||||
|
||||
(defn- pr-atom [a writer opts s]
|
||||
(-write writer (str "#<" s " "))
|
||||
(pr-writer (binding [*ratom-context* nil] (-deref a)) writer opts)
|
||||
(-write writer ">"))
|
||||
(defn- pr-atom [a writer opts s v]
|
||||
(-write writer (str "#object[reagent.ratom." s " "))
|
||||
(pr-writer (binding [*ratom-context* nil] v) writer opts)
|
||||
(-write writer "]"))
|
||||
|
||||
|
||||
;;; Queueing
|
||||
|
@ -169,7 +169,7 @@
|
|||
(-meta [_] meta)
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [a w opts] (pr-atom a w opts "Atom:"))
|
||||
(-pr-writer [a w opts] (pr-atom a w opts "RAtom" {:val (-deref a)}))
|
||||
|
||||
IWatchable
|
||||
(-notify-watches [this old new] (notify-w this old new))
|
||||
|
@ -232,7 +232,8 @@
|
|||
(-hash [_] (hash [f args]))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [a w opts] (pr-atom a w opts "Track:")))
|
||||
(-pr-writer [a w opts] (pr-atom a w opts "Track" {:val (-deref a)
|
||||
:f f})))
|
||||
|
||||
(defn make-track [f args]
|
||||
(Track. f args nil))
|
||||
|
@ -306,7 +307,8 @@
|
|||
(-swap! [a f x y more] (-reset! a (apply f (._peek a) x y more)))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [a w opts] (pr-atom a w opts (str "Cursor: " path)))
|
||||
(-pr-writer [a w opts] (pr-atom a w opts "RCursor" {:val (-deref a)
|
||||
:path path}))
|
||||
|
||||
IWatchable
|
||||
(-notify-watches [this old new] (notify-w this old new))
|
||||
|
@ -506,7 +508,7 @@
|
|||
(-equiv [o other] (identical? o other))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [a w opts] (pr-atom a w opts (str "Reaction " (hash a) ":")))
|
||||
(-pr-writer [a w opts] (pr-atom a w opts "Reaction" {:val (-deref a)}))
|
||||
|
||||
IHash
|
||||
(-hash [this] (goog/getUid this)))
|
||||
|
@ -596,7 +598,7 @@
|
|||
(-remove-watch [this key] (remove-w this key))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [a w opts] (pr-atom a w opts "Wrap:")))
|
||||
(-pr-writer [a w opts] (pr-atom a w opts "Wrapper" {:val (-deref a)})))
|
||||
|
||||
(defn make-wrapper [value callback-fn args]
|
||||
(->Wrapper value
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(ns reagenttest.testratom
|
||||
(:require [clojure.test :as t :refer-macros [is deftest testing]]
|
||||
[reagent.ratom :as rv :refer-macros [run! reaction]]
|
||||
[reagent.debug :as debug :refer-macros [dbg]]
|
||||
[reagent.debug :as debug :refer-macros [dbg dev?]]
|
||||
[reagent.core :as r]))
|
||||
|
||||
(defn fixture [f]
|
||||
|
@ -468,3 +468,18 @@
|
|||
state (with-meta (r/atom value) meta-value)]
|
||||
(is (= (meta state) meta-value))
|
||||
(is (= @state value))))
|
||||
|
||||
(deftest print-ratom-test
|
||||
(let [x (r/atom {:foo 1})]
|
||||
(is (= "#object[reagent.ratom.RAtom {:val {:foo 1}}]"
|
||||
(pr-str x)))
|
||||
(is (= "#object[reagent.ratom.RCursor {:val 1, :path [:foo]}]"
|
||||
(pr-str (r/cursor x [:foo]))))
|
||||
(is (= "#object[reagent.ratom.Wrapper {:val 1}]"
|
||||
(pr-str (r/wrap (:foo @x) #(reset! x %)))))
|
||||
(is (= (if (dev?)
|
||||
"#object[reagent.ratom.Track {:val 1, :f #object[reagenttest$testratom$foo]}]"
|
||||
"#object[reagent.ratom.Track {:val 1, :f #object[Function]}]")
|
||||
(pr-str (r/track (fn foo [] (:foo @x))))))
|
||||
(is (= "#object[reagent.ratom.Reaction {:val 1}]"
|
||||
(pr-str (reaction (:foo @x)))))))
|
||||
|
|
|
@ -1124,7 +1124,7 @@
|
|||
(deftest test-object-children
|
||||
(is (= "<p>foo bar1</p>"
|
||||
(rstr [:p 'foo " " :bar nil 1])))
|
||||
(is (= "<p>#<Atom: 1></p>"
|
||||
(is (= "<p>#object[reagent.ratom.RAtom {:val 1}]</p>"
|
||||
(rstr [:p (r/atom 1)]))))
|
||||
|
||||
(deftest test-after-render
|
||||
|
|
Loading…
Reference in New Issue