IlyaSemenov / grammy-scenes

Nested named scenes for grammY
MIT License
27 stars 0 forks source link

Remove ctx.scene.arg #2

Open IlyaSemenov opened 2 years ago

IlyaSemenov commented 2 years ago

ctx.scene.arg is needed but feels like a hack. Also, I didn't find a way to enforce typings on it.

It is used for passing initial data to top-level or nested scenes, and also to "return" data when a nested scene exits and the outer scene proceeds. I was considering merging it with ctx.scene.session but I'm not sure how (and if that's a reasonable approach at all).

IlyaSemenov commented 1 year ago

I'm inclined to getting rid of it. Basically, there are 3 different cases for the arg:

Calling new scene

Calling ctx.scene.call("subscene", arg) could save arg into ctx.scene.session of the new scene instead.

"Go to" within the scene

Basically, we can get rid of arg. If the user needs it, they can use typed ctx.scene.session to pass data around.

Accessing result of calling a nested scene

This is useful in certain scenarios, but I don't know how to handle it without ctx.scene.arg? Unlike calling scene when we can simply treat argument as the initial value of theirs session, we can't put the return value into ours session as we will lose valuable data.

May be call it ctx.scene.exitValue (similar naming to bash exit code)?