DX: Preload user and dev.user namespace (#19927)

Preload the user namespace (src/user.cljs and src/dev/user.cljs) for the mobile
target and for dev-only purposes. The files are git-ignored.

Just a reminder that you'll be responsible for making sure your user namespace
is correct. If it's broken in any way (e.g. calling non-existent code) the app
will crash at initialization (dev-only environment obviously).

Why? When the app initializes, it loads namespaces that were required at least
once. If you create a user namespace, it won't be automatically required for
you. And if you, like some Clojure devs, like to use the user namespace as
your safe heaven for experimentation and dev-only utilities, you'll need to
remember to evaluate the namespace at least once.

This is tedious and many times I forgot to do so and the app crashed because the
compiler didn't know where the symbols were coming from.
This commit is contained in:
Icaro Motta 2024-05-10 13:17:26 -03:00 committed by GitHub
parent 037e71bc03
commit 225e3b1c2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 1 deletions

View File

@ -1,4 +1,5 @@
{:config-paths ["status-im"] {:config-paths ["status-im"]
:output {:exclude-files ["src/user.cljs" "src/dev/user.cljs"]}
:lint-as {legacy.status-im.utils.views/defview clojure.core/defn :lint-as {legacy.status-im.utils.views/defview clojure.core/defn
legacy.status-im.utils.views/letsubs clojure.core/let legacy.status-im.utils.views/letsubs clojure.core/let
reagent.core/with-let clojure.core/let reagent.core/with-let clojure.core/let

2
.gitignore vendored
View File

@ -127,6 +127,8 @@ fastlane/README.md
# Clj # Clj
.cpcache/ .cpcache/
src/user.cljs
src/dev/user.cljs
# emacs # emacs
.dir-locals.el .dir-locals.el

View File

@ -53,7 +53,14 @@
:dev {:devtools {:before-load-async status-im.setup.hot-reload/before-reload :dev {:devtools {:before-load-async status-im.setup.hot-reload/before-reload
:after-load-async status-im.setup.hot-reload/reload :after-load-async status-im.setup.hot-reload/reload
:build-notify status-im.setup.hot-reload/build-notify :build-notify status-im.setup.hot-reload/build-notify
:preloads [re-frisk-remote.preload :preloads [;; We preload user namespaces so that
;; their symbols are available without
;; the developer having to manually
;; evaluate them after app
;; initialization.
user
dev.user
re-frisk-remote.preload
status-im.setup.schema-preload status-im.setup.schema-preload
;; In order to use component test helpers in the REPL we ;; In order to use component test helpers in the REPL we
;; need to preload namespaces that are not normally required ;; need to preload namespaces that are not normally required

23
src/dev/README.md Normal file
View File

@ -0,0 +1,23 @@
# The `dev/` directory
The `src/dev/` directory is a place where developers can commit non-production
and non-test code which can facilitate development in general. The code should,
ideally, be useful to more than one team member.
**Note**: As of today (2024-05-07), we don't have further guidelines or examples
about how mobile teams should use and maintain these dev-only namespaces. Before
opening a PR introducing new dev-only namespaces, consider sharing and
discussing with as many team members as you can.
### The `user` namespace
You may optionally create a `src/dev/user.cljs` and/or `src/user.cljs` file.
These files are git-ignored and are meant to be your own playground. Clojure
developers usually use such namespaces to create temporary utilities and
experiments that aren't necessarily useful to others. They are particularly
valuable for developers adept at the REPL-Driven Development workflow.
Be careful with `make clean` because it will delete all non-tracked git files.
If you rely on this file, you may prefer to create a symbolic link and store the
original `user.cljs` file outside the `status-mobile` repository. Then, after
`make clean`, you will need to recreate the symlink.