ComponentBoxService
wraps Zipline
to load and manage a Component Box.
- It sets up a single-threaded executor service for Zipline and a corresponding coroutine dispatcher.
- The
launch
function takes amanifestUrl
and starts the process of downloading, caching, and loading theKotlin/JS
code usingZiplineLoader
. - The loaded Component Box is stored in a mutable state flow called
stateFlow
, which allows observing and reacting to state changes of the loaded component. - The close function shuts down the executor service, effectively stopping
Zipline
.
- To use
ComponentBoxService
in your project, create an instance of it, passing aCoroutineScope
:
val componentBoxService = ComponentBoxService(scope = CoroutineScope(Dispatchers.Main))
- Then, call the launch function with a manifest URL:
componentBoxService.launch("http://localhost:8080/manifest.zipline.json")
- You can observe the state of the loaded Component Box using the
componentBox
property:
val componentBox = componentBoxService.componentBox.collectAsState()
- Finally, don't forget to call the close function when you're done using the ComponentBoxService:
componentBoxService.close()