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

fix: magic methods on component not being called #151

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

adamzero1
Copy link
Contributor

The documented magic methods don't appear to work for "standard" components.
The logic described in the docs (calling updated / updatedPROP) only seems to be implemented for the SyncInput action.

Should now be in place for the set method also.

@wpoortman
Copy link
Collaborator

@adamzero1,

Is this also the way Livewire V2 does it to avoid this be a breaking change as soon as I release Magewire V3?

@sprankhub
Copy link

It's really confusing that this doesn't work. The docs mention $set specifically:

This hook method is only called if the update is done through Magewire, for example via $set().

I also don't see a reason why it shouldn't work in this case. In which cases are the hooks called, then?

I really think this should be picked up.

@wpoortman
Copy link
Collaborator

Hi Simon,

Thank you for your response.

As mentioned to @adamzero1, we first need to verify if this works the same way in Livewire. Additionally, the documentation you're referencing is written by Hyvä, and I am unsure if it was thoroughly tested before publication.

Could you please test this yourself to confirm? This will allow me to proceed with merging and releasing it.

In the meanwhile you can replace $set() with your own setMyVariableValue() and you have the same result.

Thanks!

@sprankhub
Copy link

I cannot test this in Livewire myself at the moment, I'm afraid.

Either I don't understand your workaround or it doesn't work... In both versions, the hook method updatedTestComponentCounter is not called:

<button wire:click="setTestComponentCounter(<?= $magewire->testComponentCounter + 1 ?>)">Increase!</button>

(plus, having implemented a setTestComponentCounter in the component)

<button wire:click="$set('testComponentCounter', <?= $magewire->testComponentCounter + 1 ?>)">Increase!</button>

Am I missing something? 👀

@wpoortman
Copy link
Collaborator

Why do you want a hook method to act when you have your own setTestComponentCounter that does the same thing. I think you're staring at hook methods too much at the moment 😄 where just a regular method call can do the same. This is why I think method hooks for a wire:click not have hook methods and only those who use a sync like wire:model do. But that needs to be clarified first before we merge this in.

Reason why is that I'm trying to stick as close as possible to Livewire for now to avoid big bic when wanting to migrate to Magewire V3 in the future. There is an option we part ways with having everything identical, but that decision will be made after releasing V3.

So for now you should be able to proceed and leave those "magic" methods behind. Please feel free to DM me on Discord or Slack if you have any related questions regarding this topic.

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.

3 participants