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

Feature: Generic typed Loader/Renderer interface #7

Closed
3 tasks
tylermmorton opened this issue Nov 8, 2023 · 0 comments
Closed
3 tasks

Feature: Generic typed Loader/Renderer interface #7

tylermmorton opened this issue Nov 8, 2023 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@tylermmorton
Copy link
Owner

tylermmorton commented Nov 8, 2023

In the current version of the torque API, Loader and Renderer simply use the any type to describe the loader data.

type Loader interface {
	Load(req *http.Request) (any, error)
}

type Renderer interface {
	Render(wr http.ResponseWriter, req *http.Request, loaderData any) error
}

It would be great for API ergonomics to be able to declare them using a generic combination interface:

Illustration:

type GenericRenderer[T any] interface {
	Load(req *http.Request) (T, error)
	Render(wr http.ResponseWriter, req *http.Request, loaderData T) error
}

Rough outline of solution:

  • Implement new generic interface type from above in module.go.
  • Update handleLoader and handleRenderer in server.go to support the new interface type. This may or may not be possible with the generic type.
  • Add documentation to the docsite and provide guidance on API usage.
@tylermmorton tylermmorton added enhancement New feature or request help wanted Extra attention is needed labels Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant