r/Clojurescript • • Aug 27 '21

Dynamically loading libraries in runtime

Hi all,

I'm building an application in ClojureScript which should be able to load 3rd party ClojureScript libraries in the runtime. The application is not aware of any 3rd party libraries (during compile time), it should just provide a way to load them in runtime via e.g. JS file. Each 3rd party library should have some kind of an "interface" which the application understands. In this case a `(def components [<all components in this lib>])`.

Basically how I see it:

  1. load 3rd party library
  2. fetch available components from 3rd party lib
  3. use components
  4. (unload 3rd party lib)

I've done some research and all I could find is code-splitting articles which do not work in this case, since the application is not aware of any 3rd party modules.

Can anybody post a link to an article or a framework which could help me? I'm interested in which tool to use to build 3rd party ClojureScript libraries, how to load (and unload) them and how to access namespace of a library.

Best regards

6 Upvotes

2 comments sorted by

View all comments

Show parent comment

5

u/yogthos Aug 27 '21

Sci should actually work for this use case. You could create an atom that contains a registry, and add/remove evaluated code from there.