-
Setup: I am using a Laravel presence broadcast channel in order to send data back and forth to the page in this example. This is not causing the issue I am seeing, but just wanted to put that out there if someone wasn't familiar with some of the code below. I am take code I am working on a mocked up a simple hello word type example so demo the issue I am seeing. Hopefully you can follow my setup. app.js
livewire component class
livewire component view - world-test.blade.php
livewire component view - world-test.blade.php The
So either I am doing something wrong, which is certainly possible, or there is a bug in Alpine when setting a If you made is this far, then thanks for reading! Note: @calebporzio I tested this on v3.0.6 and v3.1.1 of Alpine and got same results. My issue might be what discussion #1621 is seeing too. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Okay I created an example on phpsandbox and then create a repo for it. Repo: https://github.com/delta1186/alpine-issue Be sure to open your browser's console. I just wanted to go ahead and remove the broadcast channel stuff from the discussion. As you will see when you click the button in livewire component it updates the I think this has something to do with the factor that x-data implements a callback and so it works with the proxy returned by entangle. alpine/packages/alpinejs/src/datas.js Lines 4 to 6 in 58145b3 Where $store uses different method of assigning the value. alpine/packages/alpinejs/src/store.js Lines 6 to 18 in 58145b3 My guess is since the entangle is an Object / Proxy, however that works, it gets evaluated in line 16. But really that is just a guess. @calebporzio hopefully all of this information is helpful. |
Beta Was this translation helpful? Give feedback.
-
@delta1186 <div x-data="{ show: false }" x-init="show = @entangle('show')"> So it doesn't surprise me that you can't currently use I would suggest that this is actually a Livewire issue, not Alpine one, as the Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
I was able to come up with a solution for my use case. I still think being able to set the Use case: Here is a bit of background context. Before I just made a avatar livewire component and hooked up my listeners to the same echo presence channel mentioned above. Now the issue with this implementation, was that if X rows were displayed, then livewire would first off make X different postbacks after the HERE event was fired on the presence channel. This obviously wasn't going to work, as it would cause the browser to become un-responsive until the requests had all completed. You can imagine what would happen when the JOINING and LEAVING events started firing. Interesting side note here. We had this implemented using Vue. Same setup, but for whatever reason I never saw the X number of requests. I am guessing Vue evaluates the requests before sending and if they are all the same, just sends a single request. Back to the solution. Now hopefully you can see why I wanted to use the new $store functionality. So in my livewire data table of users I have a blade component
Guess I am starting at the end and working backwards. So since this html is dynamic because the user who is online might not be displayed in the initial paginated list of users, you have to set Now for the fun part. How was I able to set my
I set a That's it and now everything works perfectly! I hope that this post helps someone down the road figure out how to find a creative solution when something does not work as you might have originally expected. This type of problem solving is one of the reasons I do enjoy programming. |
Beta Was this translation helpful? Give feedback.
I was able to come up with a solution for my use case. I still think being able to set the
$store.someVar
in thex-init
would be handy. But now understanding the current constraints here was my approach. I am going to just cut and past snippets from my code, so it won't follow the above example. Hopefully you can follow along.Use case:
I have a livewire component that listens to a laravel echo presence channel that displays all of the users currently online. Here I need to store an array of online user ids to be used by a completely separate livewire component. That livewire component is a livewire data table with searching, sorting, and pagination. And more specifically the table is a d…