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

Allow to use ComponentName::class with emitTo method. #2793

Merged
merged 5 commits into from May 3, 2021
Merged

Allow to use ComponentName::class with emitTo method. #2793

merged 5 commits into from May 3, 2021

Conversation

mateusjunges
Copy link
Contributor

This PR allows users to use the component classname when using emitTo method:

$this->emitTo(TestComponent::class, 'testEvent')

It does not introduce any breaking changes, and it's beneficial if developers want to rename components and have many emitTo calls in their projects.

2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.
No.

3️⃣ Does it include tests, if possible? (Not a deal-breaker, just a nice-to-have)
Yes.

@mateusjunges mateusjunges changed the title Patch 1 Allow to use ComponentName::class with emitTo method. Apr 29, 2021
@calebporzio
Copy link
Collaborator

Thanks for the PR! I agree with this being a good addition, however I'd like to keep the implementation inline with other similar features.

See this recent PR for a good implementation: #2755

@mateusjunges
Copy link
Contributor Author

@calebporzio Done!

@mateusjunges
Copy link
Contributor Author

@calebporzio Actually, i don't know if you want it as it is right now or with ternary if:

if ($this->component) $output['to'] = is_subclass_of($this->component, Component::class) 
    ? $this->component::getName() 
    : $this->component;

IMHO this implementation is much more readable:

if ($this->component) {
    if (is_subclass_of($this->component, Component::class)) {
        $this->component = $this->component::getName();
    }

    $output['to'] = $this->component;
}

what are your thoughts on this?

@calebporzio
Copy link
Collaborator

Ternary looks better to me. Thanks!

@mateusjunges
Copy link
Contributor Author

@calebporzio done!

@calebporzio calebporzio merged commit 6c45c16 into livewire:master May 3, 2021
@calebporzio
Copy link
Collaborator

Thanks!!!

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

Successfully merging this pull request may close these issues.

None yet

2 participants