feat(runtime-core): set currentInstance during hook execution for custom directives(close: #5002)
This PR sets currentInstance before hook calls, unsets it afterwards.
This allows for the following APIS to be used in custom directives:
-
getCurrentInstance() -
inject() -
provide() - lifecycle hooks like
onUpdated()(not sure if this is a good idea)
Alternatives
I'm not yet convinced that this is the best solution.
Specifically, I'm not sure if the breadth of "setup" APIs exposed to custom directives by this is really desirable, or if we should limit it to provide/inject, for which we could expose special versions through binding() on the binding - i.e binding.inject()? That would require more new code to be introduced though.
close: #5002
binding.inject not a good idea
exposing provide/inject indirectly via binding will be redundant, and just another non consistent way to do things.
additionally wouldn't binding the api force it into the bundle (tree shaking)
a directive hook already has access to the instance through the binding.
making getCurrentInstance() no issue.
Component life cycle hooks also have access to all these apis ( not just setup ) .
Hello, @LinusBorg! Are there any updates?