reagent/demo/reagentdemo/news/news051.cljs

103 lines
3.1 KiB
Plaintext
Raw Normal View History

2015-09-09 14:44:42 +00:00
(ns reagentdemo.news.news051
(:require [reagent.core :as r]
[reagentdemo.syntax :as s]
[sitetools.core :as tools :refer [link]]
2019-12-17 12:32:45 +00:00
[reagentdemo.common :as common :refer [demo-component]]
[clojure.string :as string]))
2015-09-09 14:44:42 +00:00
(def url "/news/news051.html")
2015-09-09 14:44:42 +00:00
(def title "News in 0.5.1")
2015-09-10 07:04:46 +00:00
(def ns-src (s/syntaxed "(ns example.core
2015-09-09 14:44:42 +00:00
(:require [reagent.core :as r]))"))
(defn old-and-tired []
[:ul
2015-09-09 15:00:49 +00:00
[:li.foo [:a.bar "Text 1"]]
[:li.foo [:a.bar "Text 2"]]])
2015-09-09 14:44:42 +00:00
(defn new-hotness []
[:ul
2015-09-09 15:00:49 +00:00
[:li.foo>a.bar "Text 1"]
[:li.foo>a.bar "Text 2"]])
(def upper-value (r/atom "FOOBAR"))
2015-09-09 14:44:42 +00:00
(defn upper-input []
2015-09-09 15:00:49 +00:00
[:div
[:p "Value is: " @upper-value]
[:input {:type 'text :value @upper-value
:on-change #(reset! upper-value
2019-12-17 12:32:45 +00:00
(-> % .-target .-value string/upper-case))}]])
2015-09-09 14:44:42 +00:00
(defn main [{:keys [summary]}]
[:div.reagent-demo
[:h1 [link {:href url} title]]
2017-11-28 17:16:26 +00:00
[:span "2015-09-09"]
2015-09-09 14:44:42 +00:00
[:div.demo-text
[:p "Reagent 0.5.1 contains a new convenient shortcut for nested
elements, better error messages, new logic for maintaining cursor
2015-09-10 07:04:46 +00:00
position in inputs, a new version of React, and some bug fixes and
improvements."]
2015-09-09 14:44:42 +00:00
(if summary
[link {:href url :class 'news-read-more} "Read more"]
[:div.demo-text
[:h2 "New syntax for nested elements"]
[:p "The ”Hiccup syntax” used in Reagent now supports defining
nested elements using ”>” as a separator in keywords. This is
probably easier to show than to explain…"]
[:p "So, instead of doing this: "]
[demo-component {:comp old-and-tired
:src (s/src-of [:old-and-tired])}]
[:p "you can now do this: "]
[demo-component {:comp new-hotness
:src (s/src-of [:new-hotness])}]
[:p "with identical results, thus saving several square
brackets from an untimely death."]
2015-09-09 14:44:42 +00:00
[:h2 "Keeping position"]
[:p "Reagent now tries harder to maintain cursor position in
text inputs, even when the value of the input is transformed in
code."]
[:p "Previously, the cursor would jump to the end of the text
2015-09-10 07:04:46 +00:00
whenever you made a change in the middle of the text in
something like this:"]
2015-09-09 14:44:42 +00:00
[demo-component {:comp upper-input
2015-09-09 15:00:49 +00:00
:src [:pre ns-src
(s/src-of [:upper-value :upper-input])]}]
2015-09-09 14:44:42 +00:00
[:h2 "Other news"]
[:ul
[:li "React is updated to 0.13.3."]
2015-09-10 07:04:46 +00:00
[:li "A bit better error messages. In particular, the current
2015-09-09 14:44:42 +00:00
component path is now printed when an exception is thrown."]
2015-09-10 07:04:46 +00:00
2015-09-09 14:44:42 +00:00
[:li "There is a new
function, " [:code "reagent.core/force-update"] " that will
make a component render immediately. It takes an optional
2015-09-10 07:04:46 +00:00
second parameter that forces re-rendering of every child
component as well."]
[:li "Calling the result
of " [:code "reagent.core/create-class"] " as a function is
now deprecated. Use Hiccup syntax instead."]
2015-09-09 14:44:42 +00:00
[:li "Some other bug fixes and performance tweaks."]]])]])
(tools/register-page url [#'main] title)