momentum-modal
momentum-modal copied to clipboard
feat: add support for lazy props in modals
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 the array_filter
has been done https://github.com/inertiajs/inertia-laravel/blob/master/src/Response.php#L148
We 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 https://github.com/lepikhinb/momentum-modal-plugin/pull/4 to work properly
Fixes: #13
Props can go back to their unflattened form when https://github.com/inertiajs/inertia-laravel/pull/435 is released
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)
- The props are now passed as a parameter to the constructor.
- The with method is used to set the props instead of passing them directly in the constructor.
- A new array $flatProps is created and it's populated by looping through all keys/values from $this->props, adding 'modal.' before each key name (e.g: modal.$key). This array will be merged into inertia()->share().
- Inertia::share() no longer receives an associative array for "modal" but only its component name ($this->component) and an indexed array containing all flatProps values (...$flatProps).
@lepikhinb Do you have an idea yet whether you will merge this PR? :)
@jeffreyvanhees still not sure about the implementation