-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
Serva is interface-less, meaning that there is no way for developers to use the application instance. We need a way for files that mount to be able to plugin into the application without the developer knowing. This becomes more apparent when exploring hooks. We want routes to be able to define specific hooks for that route. Currently there is no way to do so as we expect the default export to be a callback.
Proposal
Factories will help perform some kind of "on mount" action before it mounts it to the application. The signature of a factory could be as follows:
import { factory } from "https://serva.land/serva@latest/mod.ts";
export default factory(async (api, meta) => {
await api.task();
// return what should be mounted
return () => {};
});Factories should accept two arguments. An api that the factory provides to consumers to increase the functionality of the current mount. meta, which will be any additional values or information that may come useful to the developer when using factories.
It should be noted that factories are not required, we should always be able to mount the default export.
The application should have some mechanism to identify that the default export is a factory and handle it accordingly. For example, if we were to use a route factory the application should be able to mount the route it returns/resolves.