feat(runtime-core): directive install hook
add install hook for custom directive.
functional directive vs install hook.
currently providing a function as a directive, registers the function for created and mounted hooks
without a way to be called by other directive life cycle hooks, or knowing which hook invoked the function.
directives: {
directiveA: directiveHook(){}
}
with install hook
install function allows for setting any of the available hooks.
example: installing a directive provided by parent
/**
return { created, mounted, unmounted , ...}
*/
function providedDirectiveInstall(binding){
// we can't use inject() api but we can access via binding
let providedDirectiveOptions = binding.instance.$.provides['someDirective']
return providedDirectiveOptions
}
directives: {
myProvidedDirective: { install: providedDirectiveInstall }
}
This should go through an RFC in the rfcs repo.
Not sure if let providedDirectiveOptions = binding.instance.$.provides['someDirective'] is supported 🤔
This should go through an RFC in the rfcs repo.
agreed
Not sure if
let providedDirectiveOptions = binding.instance.$.provides['someDirective']is supported 🤔
not sure what you mean by "supported", the functionality will work, however it was just an example for possible use case for having a hook that early in the directive life cycle.
ideally inject() would have been available in directive invocation, but that might require another rfc.
RFC discussion https://github.com/vuejs/rfcs/discussions/367