fix $wire.emit, $wire.emitUp and $wire.emitTo (fixes #2498) #2618
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1️⃣ Is this something that is wanted/needed? Did you create an issue / discussion about it first?
Issue exists at #2498, but appears to be larger than what is reported there. I ran into this while playing w/ LW and trying to use
@click="$wire.emitUp('sortBy', 'column_name')
. This caused athis.componentsListeningForEventThatAreTreeAncestors is undefined
error. Changing to$wire.emit
changed the error tothis.listeners.call is undefined
, as noted in #2498, and$wire.emitTo
was causingthis.getComponentsByName is undefined
. Basically,this
was being bound incorrectly when forwarding these calls to the store. This change corrects that by removing the.apply(component, args)
code and simply calling those methods directly on the store viastore[property](...args)
.Also, it seems that
emitUp
should be receiving special handling likeemitSelf
(because it needs to receive the component element), but wasn't, so I have added a case to handle that.Please note that this is my first PR here, and I've only been using LW for ~1 week, so I may just be me misunderstanding things, but this change was enough to get me up and running again w/
$wire.emit
,$wire.emitUp
and$wire.emitTo
.2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.
No, all of this code was needed to getting
$wire.emit*
working.3️⃣ Does it include tests, if possible? (Not a deal-breaker, just a nice-to-have)
Yes. I have added a dusk test to do a basic check of each of the
$wire.emit*
methods. Before this change, only$wire.emitSelf
appears to be working. W/ this change, all of the$wire.emit*
methods are working.Please note that I've only tested this in Safari as I can't seem to get Chrome to work w/ Dusk.
4️⃣ Please include a thorough description of the improvement and reasons why it's useful.
Check: see 1️⃣ 😄
5️⃣ Thanks for contributing! 🙌
Thank you for Livewire!