Polish example

This commit is contained in:
Tommi Reiman 2018-12-17 20:54:36 +02:00
parent 492d5e2f2b
commit 7c7b8dd8a5

View file

@ -1,11 +1,11 @@
(ns frontend.core (ns frontend.core
(:require [reagent.core :as r] (:require [reagent.core :as r]
[reitit.frontend :as rf] [reitit.frontend :as rf]
[reitit.frontend.easy :as rfe] [reitit.frontend.easy :as rfe]
[reitit.coercion :as rc] [reitit.coercion :as rc]
[reitit.coercion.schema :as rsc] [reitit.coercion.schema :as rsc]
[schema.core :as s] [schema.core :as s]
[fipp.edn :as fedn])) [fipp.edn :as fedn]))
(defn home-page [] (defn home-page []
[:div [:div
@ -19,7 +19,7 @@
[:button [:button
{:type "button" {:type "button"
:on-click #(rfe/replace-state ::item {:id 4})} :on-click #(rfe/replace-state ::item {:id 4})}
"Replace State Item 4"] ]) "Replace State Item 4"]])
(defn about-page [] (defn about-page []
[:div [:div
@ -52,25 +52,25 @@
[:pre (with-out-str (fedn/pprint @match))]]) [:pre (with-out-str (fedn/pprint @match))]])
(def routes (def routes
(rf/router [["/"
["/" {:name ::frontpage
["" :view home-page}]
{:name ::frontpage
:view home-page}] ["/about"
["about" {:name ::about
{:name ::about :view about-page}]
:view about-page}]
["item/:id" ["/item/:id"
{:name ::item {:name ::item
:view item-page :view item-page
:parameters {:path {:id s/Int} :parameters {:path {:id s/Int}
:query {(s/optional-key :foo) s/Keyword}}}]] :query {(s/optional-key :foo) s/Keyword}}}]])
{:data {:coercion rsc/coercion}}))
(defn init! [] (defn init! []
(rfe/start! routes (rfe/start!
(fn [m] (reset! match m)) (rf/router routes {:data {:coercion rsc/coercion}})
{:use-fragment true}) (fn [m] (reset! match m))
{:use-fragment true})
(r/render [current-page] (.getElementById js/document "app"))) (r/render [current-page] (.getElementById js/document "app")))
(init!) (init!)