Core Package
🫀 What is Core?
Introduction
This is the entry point for initialing the application.
Options
Services
Services is a simple abstraction layer that makes some assumptions around common api requests and responses. Sevices rely on an underlying adapter which is responsible for transforming the request/response payloads and handling the actual requests to an api. Once you application has been configured, you can easily configure services like so. Note that boot exports the return values from createApplication
.
Global Error handling
You can catch all service errors via the configs in createApplication
. This is useful for catching a 401
status and redirecting to the log in screen.
Authoring Api Adapters
Api adapters run the underlying logic for services. If your api uses an SDK you might need to create a custom adapter. Start by creating an api provider function.
Next, define the actual api adapter. Make sure the class conforms with the ApiAdapterInterface
interface.
Users can register your api adapter like so
Authoring plugins
The main reason to author your own plugin is to add and enrich functionality of the application with the use of the configuration setup. To get started you'll need to define an function which provides the following
Name - Required
An arbitrary name for your plugin. This and the "root" needs to be unique because a combination of both is used as a key for lookup.
Root - Optional
If you are writing an "adapter" for a specific plugin, you may specify the root plugin name. You plugin will now be scoped under this root plugin.
Component and ComponentFactory
Components requires an app
property to be declared as a prop. It also requires a <slot />
. If the slot isn't there, your application WILL not load properly
Provide a component to be loaded with your application. There are two ways to specify how you want to load the component. You MUST specify one or the other and NOT both. The example above shows loading the component by providing it directly. You may also load the component via a factory which is an async function that returns the compoent.
Boot - optional
Called after the plugin is registerd
Handle - optional
This should return a function that conforms to svelte's hook function.