momentum-modal icon indicating copy to clipboard operation
momentum-modal copied to clipboard

feat: add support for lazy props in modals

Open Tofandel opened this issue 2 years ago • 5 comments

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

Tofandel avatar Aug 05 '22 14:08 Tofandel

Thank you for the PR. I'm going to review and either merge or re-implement this soon.

lepikhinb avatar Sep 01 '22 18:09 lepikhinb

@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)

jeffreyvanhees avatar Sep 26 '22 10:09 jeffreyvanhees

  • 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).

what-the-diff[bot] avatar Oct 24 '22 20:10 what-the-diff[bot]

@lepikhinb Do you have an idea yet whether you will merge this PR? :)

jeffreyvanhees avatar Nov 16 '22 22:11 jeffreyvanhees

@jeffreyvanhees still not sure about the implementation

lepikhinb avatar Jan 22 '23 23:01 lepikhinb