directive install hook #367
lidlanca
started this conversation in
RFC Discussions
Replies: 2 comments 6 replies
-
I like the idea - I wish I could've changed how the function shorthand worked in v3 but it's too late to make a breaking change. So
const MyDir = (el, binding) => {
// created
return {
mounted() {},
updated() {},
unmounted() {}
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
-
Is there any possibility of supporting the Composition API in the install function, like inject/provide |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Start Date: 2021-08-02
Target Major Version: 3.x
Reference Issues:
Implementation PR: feat(runtime-core): directive install hook core#4235
RFC: directive install hook #370
Summary
add
install
hook for a custom directiveBasic example
Motivation
In current state when a function is passed as a directive, vue will register the function
to
mounted
andupdated
hooks only.additionally there is no way to tell which hook invoked the function, or register to other hooks.
having an
install
hook will provide 2 main advantages.with access to the directive binding(instance, value, etc)
Why are we doing this? What use cases does it support? What is the expected
outcome?
The current function based directive is limited to 2 fixed hooks, and no ability to know the life cycle phase
when the function is invoked.
consider provide/inject api, a parent component can actually provide a directive as an
install
functionwhere the child can then inject and use.
( currently inject() is not callable in a directive hook, however as a work around, a child can "resolve" the provided value via.
instance.$.provides
)which make this use case doable. even without full support from the inject functionality.
Detailed design
vuejs/core#4235
if
install
hook is provided it will be called and the result will be merged into the directive hooks object.Drawbacks
a function based directive might have additional overhead, however vue already supports a very limited function based directive.
Alternatives
n/a
Adoption strategy
the feature is additive and should not have any impact on existing code.
Unresolved questions
is
install
the best hook nameBeta Was this translation helpful? Give feedback.
All reactions