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

Extend generic types to hooks #149

Open
Denire opened this issue Mar 15, 2021 · 1 comment
Open

Extend generic types to hooks #149

Denire opened this issue Mar 15, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@Denire
Copy link
Contributor

Denire commented Mar 15, 2021

Version 0.10.0 brought type-specific actions, e.g.:

action(telegram) { // safe-casts request and reactions type to TelegramBotRequest, TelegramReactions
    reactions.document("some-url") // use smartcasted method
}

Version 0.13.0 brought improved DSL, so we can set generic type for whole scenario.

val bot = Scenario(telegram) {
    state("state") {
        action {
            reactions.say("You said: ${request.input}", "button1", "button2")
        }
    }
}

This works great, but the only thing missing is type-casts in hooks. This issue suggests extend generic types and smart-casts to hooks. Expected DSL, generic types in handle:

handle<BeforeActionHook>(telegram) { // declare token same as in action
    reactions.document("...") // use smart-casted reactions/request/activator same as in action
}

, and generic types propagation from Scenario:

val bot = Scenario(telegram) {
    handle<BeforeActionHook> { // handle uses propagated request/reactions type
        reactions.document("...")
    }
}
@Denire Denire added the enhancement New feature or request label Mar 15, 2021
@Denire
Copy link
Contributor Author

Denire commented Apr 15, 2021

As it turns out, it's impossible to create the DSL we expected

handle<BeforeActionHook>(telegram){ ... }

because ActionHook class becomes generic and there is no way to pass generic type from type token to type declaration in hadle method.

The second solution can be that we create methods like

handleActionError { ... }
handleAnyError { ... }
handleBeforeAction { .. }
// etc

This will bring handler types closer to dsl and allow us to use type tokens inside them.

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

No branches or pull requests

1 participant