-
Notifications
You must be signed in to change notification settings - Fork 2
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
Is it possible to compose hook handlers? #2
Comments
To implement this, I suggest a "handler-combination" option. Default would be |
You are right that execution order and composition of hooks is not customizable at the moment. The current combination implementation only applies to results after all hooks have been run independently. It is like method combination without That said, I don't see why additional customization shouldn't be possible. I will have to think about how to generalize the current mechanism. Your suggestion sounds like one possibility, but the interaction with the current combination option is unclear since with |
Thanks for considering it.
Regarding the interaction with the combination, well we could raise a
warning when the user choose both #'compose for handlers #'list for
result combination. We could handle the few edge cases, but ultimately
if we let the user pass their own function, then they must be
responsible for their compatibility. It's a fair design in my opinion :)
|
Sorry for taking a long time here. I haven't forgotten about this. Despite not having a lot of time to think about this, I can say right away that I don't like the warning idea too much. I hope to combine composition and combination into a single mechanism so that the problem doesn't arise. |
I'd be happy to work on this :)
Would you accept a patch?
|
Sorry for not getting back to you earlier. I can't making any promises about accepting changes. I suggest you fork the repository and work in your fork for now. |
Intuitiveness question: cl-hooks are first-in-last-out queues. Within the context of the current issue, it would be as simple as using #'reverse as composition function. @vindarel? |
@Ambrevar Btw, are you aware of https://gitlab.com/Gnuxie/method-hooks? From a brief look, it seems to have some of the features you are proposing. |
I am, but if I'm not mistaken they only work over methods (and thus objects). I need
stand-alone hooks.
|
Say I have a hook of handlers with 1 argument returning 1 argument.
If would like to run the successive handlers of the result of the previous one.
Looking at the code of
run-hook
it does not seems possible directly.I came up with the following function:
It works, but my main concern is that this is not part of the description of the hook, the behaviour of indeed decided at the call site, not by the hook itself.
The only way to fix it, as I understand it, is to implement this "composability" feature in cl-hooks itself. Thoughts?
The text was updated successfully, but these errors were encountered: