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

Add DataCollectionSynth #591

Conversation

edalzell
Copy link
Contributor

@edalzell edalzell commented Oct 13, 2023

Going to leave this as draft because I'd like to explain my use case and see if you folks are willing to accept this. If so, I will add tests.

In my project I have a custom DataCollection called StationCollection and because I'm using Livewire (v3), I had it implement Wireable. However, the WireableSynth in Livewire expects properties:

    function set(&$target, $key, $value) {
        $target->{$key} = $value;
    }

Which throws an error when used.

To work around this I created a DataCollectionSynth that handles things properly, and then made a custom synth that inherits from DataCollectionSynth to deal with my custom stuff (mostly type hinting).

Note that to use this, one would have to add this to your service provider, Livewire::propertySynthesizer(DataCollectionSynth::class);

Does that sound reasonable?

@rubenvanassche
Copy link
Member

Hi @edalzell,

Thanks for the PR, I first need to get started with LiveWire 3 and read myself into the hydration and synthesizers part. When that's done I'll again take a look at this PR!

@edalzell
Copy link
Contributor Author

edalzell commented Dec 4, 2023

FYI, I've pulled this into my project and it works great.

@edalzell
Copy link
Contributor Author

Just pushed a fix, we need to dehydrate recursively (thanks Josh!)

@rubenvanassche
Copy link
Member

Still on my radar, now I have some time since v4 is our gonna take a look at this next week or the week after that.

@edalzell edalzell marked this pull request as ready for review February 9, 2024 15:56
@rubenvanassche rubenvanassche changed the base branch from main to data-for-livewire March 1, 2024 12:11
@rubenvanassche
Copy link
Member

Thanks!

@rubenvanassche rubenvanassche merged commit 3efe949 into spatie:data-for-livewire Mar 1, 2024
1 check passed
@edalzell edalzell deleted the feature/data-collection-synth branch May 9, 2024 04:13
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.

2 participants