-
Notifications
You must be signed in to change notification settings - Fork 0
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
Use a wrapping class for Events #14
Comments
Semantics 👍 Does this make any functionality easier for you to implement? It looks like a pretty simple change, but if it's going to require nontrivial refactors, I would keep this low priority until it blocks something else. |
The example I gave is exactly why I brought this up. In The refactors are all pretty trivial: Find/replace |
I see. Thanks for clarifying!
|
Using the class makes argument passing through middlewares much simpler (one argument vs. two + splat + double splat), and also makes assignment operations on `args` and `kwargs` possible.
Closed by #18. |
Right now, when an event gets sent up the middleware stack, the
call
method takes a specific set and arrangement of arguments:This could be simplified and made more powerful by wrapping everything up into a
Shark::Event
class. With that, thecall
definition would be much simpler:Additionally, the semantics of argument collectors (
*
, and**
) can be avoided, as everything will be wrapped up intoargs
andkwargs
attributes onEvent
.A basic outline of the class would be
Another advantage of using a wrapping class is that arguments can be freely modified out-of-place. Currently, modifying arguments either has to be done in-place (which only works in some cases, e.g.
args.map!{}
), or a replacement has to be specified when proxying an event up the middleware stack. This gets troublesome with event handlers, because there is no way to replace an argument (using=
instead of bang methods) and have that change persist outside of the handler. For example:With an
Event
class, this would look and work differently:The only thing that doesn't work here, is replacing the entire
event
object, which would be undesirable anyway.The text was updated successfully, but these errors were encountered: