/
core.cljs
68 lines (54 loc) · 2.17 KB
/
core.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(ns reacl-basics.pages.core
"A framework for page-based application.
For a standard HTML5 history page-based application, create 3 files:
my_routes.cljc
```
(ns my-routes (:require [reacl-basics.pages.routes :as r]))
(r/defroute article \"/article/:id\")
```
my_pages.cljs
```
(ns my-pages (:require [reacl-basics.pages.core :as p]
[my-routes :as my]))
(defclass article-page this app-state [id]
render ...)
(defclass main this app-state []
render
(html5-history-router (reacl/opt ...) app-state
{my/article (p/page article-page)}))
```
my_client.clj
```
(ns my-client (:require [reacl-basics.pages.ring :as r]
[reacl-basics.pages.routes :as routes]
my-routes))
(-> app
(r/wrap-client-routes routes/routes (ring-http/ok \"<html>...\")))
```
"
(:require [reacl2.core :as reacl :include-macros true]
[reacl-basics.core :as core :include-macros true]
[active.clojure.lens :as lens]
[reacl-basics.pages.router :as router]
[reacl-basics.pages.history :as history]))
(defn page
"Any class or function taking an `reacl/opt` value, an app-state and
any path arguments of the route it's assigned to, plus an optional
map of query parameters, can be used as a page. If more arguments
are required, then use this function to bind more arguments for the
page class. The class/function will be instantiated with the given
`args` before the path and query paramters."
[f & args] (if (empty? args)
f
(router/BoundPage. f args)))
(reacl/defclass ^{:doc "A Reacl class that listens to navigation events and
handles [[goto]] actions, and which renders as the
corresponding [[page]] classes from the given map of routes to
pages."} html5-history-router this app-state [pages]
render
(router/history-router (reacl/opt :embed-app-state lens/id) app-state
(history/html5-history)
pages))
(def ^{:doc "Returns an action to be handled by a wrapped history-router, instructing it to navigate to the given `path`, which may include query params."
:arglists '([path])}
goto router/goto)