Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factories #1

Open
tur-nr opened this issue Jul 1, 2020 · 0 comments · Fixed by #9 · May be fixed by #11
Open

Factories #1

tur-nr opened this issue Jul 1, 2020 · 0 comments · Fixed by #9 · May be fixed by #11
Labels
enhancement New feature or request
Milestone

Comments

@tur-nr
Copy link
Contributor

tur-nr commented Jul 1, 2020

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.

@tur-nr tur-nr added this to the Hooks milestone Jul 1, 2020
@tur-nr tur-nr added the enhancement New feature or request label Jul 3, 2020
@tur-nr tur-nr mentioned this issue Jul 7, 2020
@tur-nr tur-nr linked a pull request Jul 28, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant