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

[Proof of Concept only - Do not merge] New transformer registration method that narrows like Composer.on #92

Closed
wants to merge 1 commit into from

Conversation

KnightNiwrem
Copy link
Contributor

Screen Shot 2021-11-20 at 11 20 01 PM

@KnorpelSenf
Copy link
Member

I understand that the naming use implies that there should be similar methods like on etc, but I would prefer it if we would not have to extend the API surface for every single method we add.

Instead, we should develop a composer for API transformer functions (called Resopmoc? :D), as it is outlined in the docs at https://grammy.dev/advanced/transformers.

We could then extend the transformer type to something along the lines of MiddlewareFn | MiddlewareObj and pass this composer to bot.api.config.use. It could mirror many of the features that the original Composer has, including the implementation of on found in this PR.

@KnorpelSenf
Copy link
Member

Regarding naming, what is your opinion on consistently calling things

  • Middleware and CoMiddleware
  • Composer and CoComposer
  • Context and interface CoContext<M extends Methods<R>, R extends RawApi> { method: M, payload: Payload<M, R> } which allows for narrowing

We could then change the function parameters to (prev, cctx, signal), or optionally integrate the signal into the co-context.

@KnorpelSenf KnorpelSenf added enhancement New feature or request needs investigation Description is clear but cause is unknown labels Nov 22, 2021
@KnorpelSenf
Copy link
Member

This concept is very likely going to be added to a next major version of grammY. If you stumble upon this PR, you may be interested in reading a lengthy discussion we had about the topic today in the group chat: https://t.me/grammyjs/23758

It contains:

  • naming ideas
  • similar concepts in other fields, such as mathematics and type theory
  • why composer and co-composer are complementary
  • how composer and co-composer are similar
  • information about the scope and impact of the desired changes.

@KnorpelSenf KnorpelSenf deleted the poc-transform-on branch May 3, 2022 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs investigation Description is clear but cause is unknown
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants