@webhandle/initialize-webhandle-component
v1.0.4
Published
Boilerplate code for a module to add itself to a webhandle instance
Downloads
483
Readme
@webhandle/initialize-webhandle-component
Webhandle Components are a way to add services, templates, static files, middleware, or other code to a webhandle instance. What the component does, how it does it, and how it exposes that functionality is totally up to the component.
There are only three rules:
- A file will exist at the root of the package, initialize-webhandle-component.mjs, that will export a default async function taking a webhandle instance and options as parameters.
export default async function setup(webhandle, options) {
// something here
}The function is safe to invoke multiple times on the same webhandle instance.
The function returns an object which exposes any data or functionality that the component provides. This can be an empty object if there's no exposed functionality.
The code in this package has some ideas about what exposed functionality looks like and how to handle multiple invocations of the function. They are only suggestions and the code itself in this package only exists to prevent having to copy the same boilerplate over and over again.
Install
npm install @webhandle/initialize-webhandle-componentCreating a Component
The initialization file can be created for you by running
npx create-initialize-webhandle-component-fileThis will create the file initiailze-webhandle-component.mjs in the current directory.
Make sure to go in and change the component name and add the code needed to integrate
your functionality.
Using a Component
- Install that component via npm like:
npm install @my/component- Import and run the setup function like:
import setup from "@my/component/initialize-webhandle-component.mjs"
await setup(myWebhandleInstance, options)Component Documentation
There's lots of things you'd want to document about the what your component does, but here are the things you probably should mention to help callers access those functions.
On the server side:
- The services exposed
- The events emitted
- The static content made available
- The templates made available
On the client side:
- The js modules supplied to client code.
- The URLs at which exposed functionality is available.
