Skip to content

Commit 288d978

Browse files
committed
Add more docs
1 parent b44b0c6 commit 288d978

File tree

3 files changed

+123
-5
lines changed

3 files changed

+123
-5
lines changed

README.md

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,114 @@
1-
# Cljfx dev tools
1+
# Cljfx dev tools
2+
3+
Cljfx is a declarative, functional and extensible wrapper of JavaFX inspired by better parts of react and re-frame. Cljfx dev tools are a set of tools that can help with developing cljfx applications that should not be included into production distribution of the cljfx app.
4+
5+
## Installation
6+
7+
See latest version in Clojars
8+
9+
[//]: # (TODO: deploy to Clojars)
10+
11+
## Requirements
12+
13+
Cljfx dev tools require Java 11 or later.
14+
15+
## Tools
16+
17+
### Props and types reference
18+
19+
If you don't remember the props required by some cljfx type, or if you don't know what even are the available types, you can use `cljfx.dev/help` to look up this information:
20+
21+
```clojure
22+
(require 'cljfx.dev)
23+
;; look up information about fx type:
24+
(cljfx.dev/help :label)
25+
;; Cljfx type:
26+
;; :label
27+
;;
28+
;; Instance class:
29+
;; javafx.scene.control.Label
30+
;;
31+
;; Props Value type
32+
;; :accessible-help string
33+
;; :accessible-role either of: :button, :check-box, :check-menu-item, :combo-box, :context-menu, :date-picker, :decrement-button, :hyperlink, :image-view, :increment-button, :list-item, :list-view, :menu, :menu-bar, :menu-button, :menu-item, :node, :page-item, :pagination, :parent, :password-field, :progress-indicator, :radio-button, :radio-menu-item, :scroll-bar, :scroll-pane, :slider, :spinner, :split-menu-button, :tab-item, :tab-pane, :table-cell, :table-column, :table-row, :table-view, :text, :text-area, :text-field, :thumb, :titled-pane, :toggle-button, :tool-bar, :tooltip, :tree-item, :tree-table-cell, :tree-table-row, :tree-table-view, :tree-view
34+
;; :accessible-role-description string
35+
;; ...etc.
36+
37+
;; look up information about a prop:
38+
(cljfx.dev/help :label :graphic)
39+
;; Prop of :label - :graphic
40+
;;
41+
;; Cljfx desc, a map with :fx/type key
42+
;;
43+
;; Required instance class:
44+
;; javafx.scene.Node¹
45+
;;
46+
;; ---
47+
;; ¹javafx.scene.Node - Fitting cljfx types:
48+
;; Cljfx type Class
49+
;; :accordion javafx.scene.control.Accordion
50+
;; :ambient-light javafx.scene.AmbientLight
51+
;; :anchor-pane javafx.scene.layout.AnchorPane
52+
;; :arc javafx.scene.shape.Arc
53+
;; ...
54+
```
55+
56+
### Improved error messages with spec
57+
58+
You can set custom type->lifecycle opt that will validate all cljfx component descriptions using spec and properly describes the error:
59+
60+
```clojure
61+
;; suppose you have a simple app:
62+
(require '[cljfx.api :as fx])
63+
64+
(defn message-view [{:keys [text]}]
65+
{:fx/type :label
66+
:text text})
67+
68+
(defn root-view [{:keys [text]}]
69+
{:fx/type :stage
70+
:showing true
71+
:scene {:fx/type :scene
72+
:root {:fx/type message-view
73+
:text text}}})
74+
75+
(def state (atom {:text "Hello world"}))
76+
77+
;; you will use custom logic here to determine if it's a prod or dev,
78+
;; e.g. by using a system property: (Boolean/getBoolean "my-app.dev")
79+
(def in-development? true)
80+
81+
(def renderer
82+
(fx/create-renderer
83+
:middleware (fx/wrap-map-desc #(assoc % :fx/type root-view))
84+
;; print errors in REPL's *err* output
85+
:error-handler (bound-fn [^Throwable ex]
86+
(.printStackTrace ^Throwable ex *err*))
87+
:opts (cond-> {}
88+
;; Validate descriptions in dev
89+
in-development?
90+
(assoc :fx.opt/type->lifecycle @(requiring-resolve 'cljfx.dev/type->lifecycle)))))
91+
92+
(defn -main []
93+
(fx/mount-renderer state renderer))
94+
95+
;; then start the app:
96+
(-main)
97+
;; invalid state change - making text prop of a label not a string:
98+
(swap! state assoc :text :not-a-string)
99+
;; prints to *err*:
100+
;; clojure.lang.ExceptionInfo: Invalid cljfx description of :label type:
101+
;; :not-a-string - failed: string? in [:text]
102+
;;
103+
;; Cljfx component stack:
104+
;; :label
105+
;; user/message-view
106+
;; :scene
107+
;; :stage
108+
;; user/root-view
109+
;;
110+
;; at cljfx.dev$ensure_valid_desc.invokeStatic(validation.clj:62)
111+
;; at cljfx.dev$ensure_valid_desc.invoke(validation.clj:58)
112+
;; at cljfx.dev$wrap_lifecycle$reify__22150.advance(validation.clj:80)
113+
;; at ...
114+
```

src/cljfx/dev.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
(load "dev/help")
241241

242242
(defn help
243+
"Print help about cljfx types and props"
243244
([]
244245
(let [ts (->> @registry :types)]
245246
(println "Available cljfx types:")
@@ -344,9 +345,10 @@
344345
(wrap-type->lifecycle (some-fn fx/keyword->lifecycle fx/fn->lifecycle)))
345346

346347
;; next steps:
347-
;; - documentation
348348
;; - release on clojars
349349
;; stretch goals
350350
;; - ui reference for searching the props/types/etc
351351
;; - dev cljfx type->lifecycle wrapper that adds inspector capabilities.
352-
;; - dev ui builder
352+
;; - dev ui builder
353+
354+
(help :label :graphic)

src/cljfx/dev/validation.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
(throw (doto (ex-info
1010
(str (ex-message ex)
1111
"\n\nCljfx component stack:\n "
12-
(->> stack (map type->string) (str/join "\n ")))
13-
{::cause ex})
12+
(->> stack (map type->string) (str/join "\n "))
13+
"\n")
14+
(with-meta {::cause ex} {:type ::hidden}))
1415
(.setStackTrace (.getStackTrace ex))))))
1516

17+
(defmethod print-method ::hidden [_ _])
18+
1619
(defn- explain-str [explain-data]
1720
(->> explain-data
1821
::s/problems

0 commit comments

Comments
 (0)