2020-01-21 18:15:57 -05:00
|
|
|
# Common's guide #
|
|
|
|
|
|
|
|
This section intends to have articles that related to both frontend
|
|
|
|
and backend, such as: code style hints, architecture dicisions, etc...
|
|
|
|
|
|
|
|
|
|
|
|
## Assertions ##
|
|
|
|
|
2020-03-08 07:13:32 -05:00
|
|
|
UXBOX source code has this types of assertions:
|
2020-01-21 18:15:57 -05:00
|
|
|
|
2020-03-08 07:13:32 -05:00
|
|
|
**assert**: just using the clojure builtin `assert` macro.
|
2020-01-21 18:15:57 -05:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```clojure
|
|
|
|
(assert (number? 3) "optional message")
|
|
|
|
```
|
|
|
|
|
2020-03-08 07:13:32 -05:00
|
|
|
This asserts are only executed on development mode. On production
|
|
|
|
environment all assets like this will be ignored by runtime.
|
|
|
|
|
|
|
|
**spec/assert**: using the `uxbox.common.spec/assert` macro.
|
|
|
|
|
2020-01-21 18:15:57 -05:00
|
|
|
Also, if you are using clojure.spec, you have the spec based
|
|
|
|
`clojure.spec.alpha/assert` macro. In the same way as the
|
|
|
|
`clojure.core/assert`, on production environment this asserts will be
|
|
|
|
removed by the compiler/runtime.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
````clojure
|
2020-03-08 07:13:32 -05:00
|
|
|
(require '[clojure.spec.alpha :as s]
|
|
|
|
'[uxbox.common.spec :as us])
|
2020-01-21 18:15:57 -05:00
|
|
|
|
|
|
|
(s/def ::number number?)
|
|
|
|
|
2020-03-08 07:13:32 -05:00
|
|
|
(us/assert ::number 3)
|
2020-01-21 18:15:57 -05:00
|
|
|
```
|
|
|
|
|
2020-03-08 07:13:32 -05:00
|
|
|
In the same way as the `assert` macro, this performs the spec
|
|
|
|
assertion only on development build. On production this code will
|
|
|
|
completely removed.
|
|
|
|
|
|
|
|
**spec/verify**: An assertion type that is executed always.
|
2020-01-21 18:15:57 -05:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```clojure
|
|
|
|
(require '[uxbox.common.spec :as us])
|
|
|
|
|
2020-03-08 07:13:32 -05:00
|
|
|
(us/verify ::number 3)
|
2020-01-21 18:15:57 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
This macro enables you have assetions on production code.
|
|
|
|
|
2020-03-08 07:13:32 -05:00
|
|
|
**Why don't use the `clojure.spec.alpha/assert` instead of the `uxbox.common.spec/assert`?**
|
|
|
|
|
|
|
|
The uxbox variant does not peforms additional runtime checks for know
|
|
|
|
if asserts are disabled in "runtime". As a result it generates much
|
|
|
|
simplier code at development and production builds.
|
2020-01-21 18:15:57 -05:00
|
|
|
|