Skip to content

Commit efcdecf

Browse files
committed
Update README.md
1 parent c6e14fc commit efcdecf

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ The default developer experience of cljfx has some issues:
1414

1515
Cljfx dev tools solve these issues by providing:
1616
- reference for cljfx types and props;
17-
- specs for cljfx descriptions, so they can be validated (both individually and in running apps).
17+
- specs for cljfx descriptions, so they can be validated;
18+
- dev-time lifecycles that perform validation and add cljfx component stacks to exceptions to help with debugging;
1819

1920
## Installation
2021

@@ -112,7 +113,7 @@ You can set validating type->lifecycle opt that will validate all cljfx componen
112113
:opts (cond-> {}
113114
;; Validate descriptions in dev
114115
in-development?
115-
(assoc :fx.opt/type->lifecycle @(requiring-resolve 'cljfx.dev/validating-type->lifecycle)))))
116+
(assoc :fx.opt/type->lifecycle @(requiring-resolve 'cljfx.dev/type->lifecycle)))))
116117

117118
(defn -main []
118119
(fx/mount-renderer state renderer))
@@ -137,7 +138,7 @@ You can set validating type->lifecycle opt that will validate all cljfx componen
137138
;; at cljfx.dev$wrap_lifecycle$reify__22150.advance(validation.clj:80)
138139
;; at ...
139140
```
140-
If you already use custom type->lifecycle opt, instead of using `cljfx.dev/validating-type->lifecycle` you can use `cljfx.dev/wrap-validating-type->lifecycle` to wrap your type->lifecycle with validations.
141+
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.
141142

142143
Additionally, you can validate individual descriptions while developing:
143144
```clojure

src/cljfx/dev.clj

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@
319319

320320
(load "dev/validation")
321321

322-
(defn wrap-validating-type->lifecycle
322+
(defn wrap-type->lifecycle
323323
"Wrap type->lifecycle used in the cljfx UI app with improved error messages
324324
325325
Wrapped lifecycle performs spec validation of cljfx descriptions that results
@@ -328,21 +328,21 @@
328328
Additionally, exceptions thrown during cljfx lifecycle show a cljfx component
329329
stack to help with debugging.
330330
331-
Args:
331+
Optional kv-args:
332332
type->lifecycle the type->lifecycle fn used in opts of your app
333333
type->id custom type->id if you need a way to get id from your
334334
custom lifecycles"
335-
([type->lifecycle]
336-
(wrap-validating-type->lifecycle type->lifecycle *type->id*))
337-
([type->lifecycle type->id]
338-
(let [f (memoize wrap-lifecycle)]
339-
(fn [type]
340-
(f type type->lifecycle type->id)))))
341-
342-
(def validating-type->lifecycle
335+
[& {:keys [type->lifecycle type->id]
336+
:or {type->lifecycle *type->lifecycle*
337+
type->id *type->id*}}]
338+
(let [f (memoize wrap-lifecycle)]
339+
(fn [type]
340+
(f type type->lifecycle type->id))))
341+
342+
(def type->lifecycle
343343
"Default type->lifecycle that can be used in the cljfx UI app to improve error
344344
messages"
345-
(wrap-validating-type->lifecycle (some-fn fx/keyword->lifecycle fx/fn->lifecycle)))
345+
(wrap-type->lifecycle))
346346

347347
(defn explain-desc
348348
"Validate cljfx description and report any issues
@@ -351,16 +351,14 @@
351351
type->lifecycle the type->lifecycle fn used in opts of your app
352352
type->id custom type->id if you need a way to get id from your
353353
custom lifecycles"
354-
([desc]
355-
(explain-desc desc *type->lifecycle* *type->id*))
356-
([desc type->lifecycle]
357-
(explain-desc desc type->lifecycle *type->id*))
358-
([desc type->lifecycle type->id]
359-
(binding [*type->lifecycle* type->lifecycle
360-
*type->id* type->id]
361-
(if-let [explain-data (s/explain-data :cljfx/desc desc)]
362-
(println (explain-str explain-data))
363-
(println "Success!")))))
354+
[desc & {:keys [type->lifecycle type->id]
355+
:or {type->lifecycle *type->lifecycle*
356+
type->id *type->id*}}]
357+
(binding [*type->lifecycle* type->lifecycle
358+
*type->id* type->id]
359+
(if-let [explain-data (s/explain-data :cljfx/desc desc)]
360+
(println (explain-str explain-data))
361+
(println "Success!"))))
364362

365363
;; stretch goals
366364
;; - ui reference for searching the props/types/etc

test/cljfx/dev_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(defn- validated [desc]
99
@(fx/on-fx-thread
1010
(-> desc
11-
(fx/create-component {:fx.opt/type->lifecycle fx.dev/validating-type->lifecycle})
11+
(fx/create-component {:fx.opt/type->lifecycle fx.dev/type->lifecycle})
1212
fx/instance)))
1313

1414
(deftest create-test
@@ -29,7 +29,7 @@
2929
:text "a string"}]}))))
3030

3131
(deftest advance-test
32-
(let [opts {:fx.opt/type->lifecycle fx.dev/validating-type->lifecycle}
32+
(let [opts {:fx.opt/type->lifecycle fx.dev/type->lifecycle}
3333
c (fx/create-component
3434
{:fx/type :label
3535
:text "foo"}
@@ -65,7 +65,7 @@
6565
old-err System/err]
6666
(System/setErr err)
6767
@(fx/on-fx-thread
68-
(let [opts {:fx.opt/type->lifecycle fx.dev/validating-type->lifecycle}
68+
(let [opts {:fx.opt/type->lifecycle fx.dev/type->lifecycle}
6969
c (fx/create-component
7070
{:fx/type :stage
7171
:showing true

0 commit comments

Comments
 (0)