Skip to content

Commit b8307d7

Browse files
committed
Add explain-desc
1 parent 42795fa commit b8307d7

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ If you don't remember the props required by some cljfx type, or if you don't kno
6868

6969
### Improved error messages with spec
7070

71-
You can set custom type->lifecycle opt that will validate all cljfx component descriptions using spec and properly describe the error:
71+
You can set validating type->lifecycle opt that will validate all cljfx component descriptions using spec and properly describe the errors:
7272

7373
```clojure
7474
;; suppose you have a simple app:
@@ -124,4 +124,34 @@ You can set custom type->lifecycle opt that will validate all cljfx component de
124124
;; at cljfx.dev$ensure_valid_desc.invoke(validation.clj:58)
125125
;; at cljfx.dev$wrap_lifecycle$reify__22150.advance(validation.clj:80)
126126
;; at ...
127+
```
128+
If you already use custom type->lifecycle opt, instead of using `cljfx.dev/type->lifecycle` you can use `cljfx.dev/wrap-type->lifecycle` to wrap your type->lifecycle with validations.
129+
130+
Additionally, you can validate individual descriptions while developing:
131+
```clojure
132+
(cljfx.dev/explain-desc
133+
{:fx/type :stage
134+
:showing true
135+
:scene {:fx/type :scene
136+
:root {:fx/type :text-formatter
137+
:value-converter :int}}})
138+
;; :int - failed: #{:local-date-time :long :double :short :date-time :number :local-time :default :float :integer :byte :local-date :big-integer :boolean :character :big-decimal} in [:scene :root :value-converter]
139+
;; :int - failed: (instance-of javafx.util.StringConverter) in [:scene :root :value-converter]
140+
141+
(cljfx.dev/explain-desc
142+
{:fx/type :stage
143+
:showing true
144+
:scene {:fx/type :scene
145+
:root {:fx/type :text-formatter
146+
:value-converter :integer}}})
147+
;; {:fx/type :text-formatter, :value-converter :integer} - failed: (desc-of (quote javafx.scene.Parent)) in [:scene :root]
148+
149+
(cljfx.dev/explain-desc
150+
{:fx/type :stage
151+
:showing true
152+
:scene {:fx/type :scene
153+
:root {:fx/type :text-field
154+
:text-formatter {:fx/type :text-formatter
155+
:value-converter :integer}}}})
156+
;; Success!
127157
```

build.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
:target-dir class-dir})
2525
(b/jar {:class-dir class-dir
2626
:jar-file jar-file})
27+
(b/git-process {:git-args ["tag" (str "v" version)]})
2728
(aether/deploy
2829
:coordinates [lib version]
2930
:jar-file jar-file
@@ -39,4 +40,5 @@
3940
String/valueOf)
4041
(do (print "Clojars token:")
4142
(flush)
42-
(read-line)))))))
43+
(read-line))))))
44+
(b/git-process {:git-args ["push" "origin" (str "v" version)]}))

src/cljfx/dev.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,18 @@
344344
messages"
345345
(wrap-type->lifecycle (some-fn fx/keyword->lifecycle fx/fn->lifecycle)))
346346

347+
(defn explain-desc
348+
([desc]
349+
(explain-desc desc *type->lifecycle* *type->id*))
350+
([desc type->lifecycle]
351+
(explain-desc desc type->lifecycle *type->id*))
352+
([desc type->lifecycle type->id]
353+
(binding [*type->lifecycle* type->lifecycle
354+
*type->id* type->id]
355+
(if-let [explain-data (s/explain-data :cljfx/desc desc)]
356+
(println (explain-str explain-data))
357+
(println "Success!")))))
358+
347359
;; stretch goals
348360
;; - ui reference for searching the props/types/etc
349361
;; - dev cljfx type->lifecycle wrapper that adds inspector capabilities.

0 commit comments

Comments
 (0)