List namespaces and dynamically load them in ClojureScript

This may actually be a bit of an XY-problem , so I’ll try to explain what the goal is in the first place.

I am creating a ClojureScript application that consists of a set of Reagent components. It provides a user interface in which you can dynamically add or remove user interface elements. These user interface elements (components) are of a specific type. For example, the Markdown is-acomponent A text component. Whenever the user is given the option to add text, we list all the components that correspond to the type + descendants (in this case, Markdown, be different there).

The way I encoded this is as follows. Each component is in its own namespace; this namespace contains a builder function that returns a new component. At the root of the namespace, it also calls ( derive :: type :: parent)

now in some other namespace we require and list all these components on the map, for example:

(ns app.components
  (:require
   [app.gui.markdown :as markdown]
   [app.gui.study-list :as study-list]))

(def all
  {markdown/t markdown/builder
   study-list/t study-list/builder})

Where /trefers to a keyword with a qualification name that was used to define the hierarchy. We use a map allto provide data for a menu that is facing the user (which components can be added, filtered by type).

, , . () .

- (def all (components-of (descendants ::root))), , , , vars ( ClojureScript).

, : + vars () ClojureScript?

+4
1

, , . ClojureScript - cljs.analyzer.api, , ( var - ) . , cljs.test/run-tests. :test, . cljs.test , .

+3

All Articles