-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat: add support for lazy props in modals #18
base: master
Are you sure you want to change the base?
Conversation
Thank you for the PR. I'm going to review and either merge or re-implement this soon. |
@lepikhinb Do you have any updates on this? It would be great when this feature is implemented. Essential for the 'modal principle' in my opinion. (No pressure, I know there are too few hours in a day) |
|
@lepikhinb Do you have an idea yet whether you will merge this PR? :) |
@jeffreyvanhees still not sure about the implementation |
$flatProps = []; | ||
foreach ($this->props as $key => $prop) { | ||
$flatProps['modal.props.'.$key] = $prop; | ||
} | ||
/** @phpstan-ignore-next-line */ | ||
inertia()->share(['modal' => $this->component()]); | ||
inertia()->share(['modal' => $this->component(), ...$flatProps]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually looping over the props can be avoided by using the Arr::dot
helper method:
inertia()->share(['modal' => $this->component(), ...Arr::dot($this->props, 'modal.props.')]);
Inertia doesn't support lazyness for nested props because it only does a simple
array_filter
, but it has a magic trick up it's sleeve that unpacks string props with dots in them after thearray_filter
has been done https://github.com/inertiajs/inertia-laravel/blob/master/src/Response.php#L148We can use that and share a flat array of modal props to inertia which will enable the lazy prop feature by using
only: ['modal.props.someProp']
This PR needs lepikhinb/momentum-modal-plugin#4 to work properly
Fixes: #13
Props can go back to their unflattened form when inertiajs/inertia-laravel#435 is released