Skip to content

Conversation

@LinusBorg
Copy link
Member

@LinusBorgLinusBorg commented Dec 4, 2021

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

Set currentInstance before hook calls close: #5002
@LinusBorgLinusBorg changed the title feat(runtime-core): allow inject() in custom directives close: #5002feat(runtime-core): set currentInstance during hook execution for custom directives(close: #5002)Dec 4, 2021
@LinusBorgLinusBorg added the need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. label Dec 4, 2021
@lidlanca
Copy link
Contributor

lidlanca commented Dec 5, 2021

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

@cmath10
Copy link

Hello, @LinusBorg! Are there any updates?

@edison1105edison1105 deleted the linusborg/feat-set-currenInstance-for-dirs-5002 branch October 21, 2024 07:37
@edison1105edison1105 restored the linusborg/feat-set-currenInstance-for-dirs-5002 branch October 21, 2024 08:22
@edison1105edison1105 reopened this Oct 21, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need guidanceThe approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

Using provide/inject in a directive

5 participants

@LinusBorg@lidlanca@cmath10@edison1105