Lifecycle
Every widget and settings page creates an EvmuxAppsApi instance, reports that it has loaded, and reads and writes the app settings object.
Create the instance
Each component, the settings page and the widget, first creates its own instance of EvmuxAppsApi:
const evmuxApi = new EvmuxAppsApi()
Report that the app has loaded
Then call reportLoaded to tell evmux that your component is ready to be displayed:
const appSettings = await evmuxApi.reportLoaded()
evmux does not display a component before it calls
reportLoaded. You can callevmuxApi.getSettings()beforereportLoaded, to make sure your app is rendered correctly before it is displayed.
A typical start, taken from the sample app:
const evmuxApi = new EvmuxAppsApi()
const { response: settings } = await evmuxApi.getSettings()
if (settings) render(settings)
await evmuxApi.reportLoaded()
The settings object
The settings object is the storage of each app instance, which is one app layer. Store your configuration and user data there.
Call getSettings at any time to get the current settings of the app:
const appSettings = await evmuxApi.getSettings()
Call updateSettings to set new settings or update them:
const result = await evmuxApi.updateSettings({ title: 'new title' })
When the settings change, every component that registered the settingsUpdated event is called with the new settings. This is how the widget follows what the user does in the settings sidebar.
Stuck, or found a mistake in these docs? Tell us.