-
Notifications
You must be signed in to change notification settings - Fork 81
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
[RFC] warn on second call to the dispatch function #30
Conversation
src/hooks.ml
Outdated
One@ should@ not@ setup@ hooks@ several@ times,@ but@ rather@ \ | ||
combine@ several@ dispatch@ functions@ explicitly@ \ | ||
in@ a@ single@ dispatch@ call.@ This@ lets@ you@ declare@ \ | ||
the@ horder@ between@ sub-hooks@ instead@ of@ relying@ \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare the border
@gasche I'd like to nominate this for inclusion in 0.11. |
ddc8ed5
to
87cbc7c
Compare
I rebased, used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
87cbc7c
to
75dc9da
Compare
@gasche can you rebase this on top of master, to trigger the build? |
75dc9da
to
de3256b
Compare
Should we merge this one ? |
Sounds reasonable. Let's |
Thanks! |
It is an embarrassing shortcoming of the plugin-tags work that calling the
dispatch
function several times just silently overrides its behaviour. Forcing users to calldispatch
exactly once may be the right interface to expose, but not saying anything if they make a mistake is bad usability.One approach would be to keep a queue of hooks, push each new hook, and call them in order at dispatch time. I decided not to do that, however, because that would encourage an imperative way to provide functionality, with each plugin doing its own
dispatch
call; this would be fairly fragile as (1) users would have little control over the ordering on plugin rules and (2) they would have to jump through hoops to make sure the plugins are really linked, otherwise their effect would get silently dropped.By forcing that there is at most one dispatch call, we in fact enforce a pure, declarative interface between plugin providers and plugin users. This has worked out rather well in practice (despite the subpar usability of the current code), see js_of_ocaml ocamlbuild plugin for example.
This PR keeps this current interface of having a single dispatch call, but adds a warning each time a previously installed hook is discarded. (The formatted warning text is rather painful to read, so I will probably convert it to one of Daniel's Bünzli nice formatting functions instead.)