Closed aerni closed 2 years ago
This does look good and does sound like a neat improvement. Thanks for the PR!
Should we ask the community if it's helpful and if it covers most use cases? I am simply thinking that it would be great having it tested somehow.
What do you think?
Erin should test it. He's got a recent use case for it.
Also, I'm not quite sure if it's a security issue to make the whole context available as public property?
Erin should test it. He's got a recent use case for it.
@edalzell
Also, I'm not quite sure if it's a security issue to make the whole context available as public property?
That's a valid point. We should look into this a little more.
When I tried this I found it really really slowed down the front end, likely cuz of all the serialization it has to do.
Another issue is that all the data must be Wireable
and in a "base" format. Only native types and a few Laravel types (Carbon, Collection, Models) are possible.
This will require more thinking.
I will close this, until we found a better solution :-)
The idea of this PR is to make the Statamic context available as public property in your Livewire components. Having the context available can help to reduce the number of properties you have to pass down the component in your view.
Simply add the
WithContext
trait to your component and you're good to go.I'm not completely sure, but one possible limitation is probably the reactivity of the context property. If you want to make certain context properties reactive, you'd still have to manually create a new livewire property and mount the context value to it. At least this would reduce the noise in your template.
Another idea could be to do some magic and automatically add all context properties as a livewire property. But this might lead to other issues as well.
Please give feedback on what you think about this idea.