core icon indicating copy to clipboard operation
core copied to clipboard

feat(runtime-core): set currentInstance during hook execution for custom directives(close: #5002)

Open LinusBorg opened this issue 4 years ago • 2 comments

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

LinusBorg avatar Dec 04 '21 11:12 LinusBorg

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 ) .

lidlanca avatar Dec 05 '21 07:12 lidlanca

Hello, @LinusBorg! Are there any updates?

cmath10 avatar Jul 20 '23 11:07 cmath10