Skip to content
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

feat(runtime-core): directive install hook #4235

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lidlanca
Copy link
Contributor

@lidlanca lidlanca commented Aug 1, 2021

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 }
}

@posva
Copy link
Member

posva commented Aug 1, 2021

This should go through an RFC in the rfcs repo.

Not sure if let providedDirectiveOptions = binding.instance.$.provides['someDirective'] is supported 🤔

@lidlanca
Copy link
Contributor Author

lidlanca commented Aug 2, 2021

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.

@lidlanca
Copy link
Contributor Author

lidlanca commented Aug 2, 2021

RFC discussion vuejs/rfcs#367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

4 participants