-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Emit param handling: allow assoc arrays and multiple emit arguments (like Livewire) #106
Conversation
I've did some testing, but we need to look into this more thoroughly since the outcome between params in Livewire and Magewire now are different which I don't favor and has always been one of my priorities. Update: |
That makes sense to keep the two in sync. Please confirm the idea is that this code $this->emit('foo_bar', ['is_complete' => true]); results in the params {"is_complete": true} and the code $this->emit('foo_bar', true, 23]); results in the params [true, 23] and the code $this->emit('foo_bar'); results in the params [] Right? |
For our Loqate module we use an empty I would change the check to this though: Same for the other line of code: This makes more sense to me because you can see it will always cast to an array and otherwise create an empty array. |
@jesse-deboer I think the code you suggested does something different. I'm not 100% sure I understand your intention because so much context is missing, but from what I can see it would change the behavior of the patch in this PR. |
@Vinai you are right, the solution in this PR fixes it, the solution I looked at the code wrong, the solution I gave does work differently and gives different results. Sorry! |
@wpoortman yes, but it should be an empty array, right? |
Not valid JSON, but added the keys to make it more clear on how it ends up in the network tab.
Livewire: [
0: {
"event": "test",
"params": []
}
] ✅ Magewire: [
0: {
"event": "test",
"params": []
}
]
Livewire: [
0: {
"event": "test",
"params": [
[
0: true,
1: "foo"
]
]
}
] ❌ Magewire: [
0: {
"event": "test",
"params": [
0: true,
1: "foo"
]
}
]
Livewire: [
0: {
"event": "test",
"params": [
0: true,
1: "foo"
]
}
] ✅ Magewire: [
0: {
"event": "test",
"params": [
0: true,
1: "foo"
]
}
]
Livewire: [
0: {
"event": "test",
"params": [
{
"foo": "bar"
}
]
}
] ❌ Magewire: [
0: {
"event": "test",
"params": [
0: "bar"
]
}
] Conclusion: there is definitely something that needs to be changed. |
db2e8f9
to
7dc2250
Compare
I've updated the MR so the params always match magewire.
|
I've updated the MR so multiple arguments to
|
The PR #104 caused an issue where an empty array is passed as an argument to emits when no arguments where specified.
The changes in this PR resolve the problem.