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 support for inertia deferred props #939

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

matthiasweiss
Copy link
Contributor

@matthiasweiss matthiasweiss commented Jan 24, 2025

Hello 👋

I've drafted up an initial version of support for inertia v2 deferred props.

Usage looks like this:

class AutoDeferredData extends Data
{
    #[AutoInertiaDeferred]
    public InertiaDeferred $deferred;
}

$data = AutoDeferredData::from(['string' => Inertia::defer(fn () => 'Deferred Value')]

I'm not really happy with the implementation, since the concept of deferred props is technically not related to lazy properties, but the implementation is basically copied 1:1. On the other hand, this kind of makes sense, since the effects of lazy and deferred properties are very similar.

My other approach would've been to basically copy the structure of the abstract Lazy, AutoLazy & InertiaLazy classes, but this would've required a bunch more changes.

However, I still don't really like how I've done it here, but I don't think this can be done a lot better without larger refactoring. Maybe a bigger refactoring even makes sense, since merging props should also be implemented.

I'm definitely open for any suggestions!

Best,
Matthias

class InertiaDeferred extends ConditionalLazy
{
public function __construct(
mixed $value,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mixed instead of DeferProps', since the $valueparameter in theAutoInertiaDeferred::build` method is mixed and needs to be passed to this function

@matthiasweiss matthiasweiss marked this pull request as ready for review January 24, 2025 22:04
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.

1 participant