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

Lightweight layout on asynchronous loading #2120

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Augen2203
Copy link
Contributor

Hello, this corrects the following points:

  • Speeds up screen loading by not rendering empty layouts, which are subsequently replaced by an async request.

  • We no longer need to predefine properties in the query() method that are equal to those that we would use in asynchronously loaded layouts.

Previously, for example, this was necessary if we used the canSee() method, like so:

->canSee($this->query->get('user')->exists).

Example:

We have an asynchronous modal window to which we pass the user model through the asyncGetUser() method, in this modal window there is a layout with a form in which, depending on whether the user exists or not, we want to hide one of the fields through a function ->canSee($this->query->get('user')->exists).

We'll get an error because when the screen first loads, $this->query->get('user') will be null,
Therefore, as one of the options, we needed to predefine it in the query() method, thus:

public function query(User $user)
{
       return [
              'user' => $user
       ];
}

In my particular case, when I use a lot of async modals, this gave me some pluses, in terms of memory, the number of layouts loaded and speed.
Снимок экрана 2022-02-09 в 00 16 06
Снимок экрана 2022-02-09 в 00 18 25

})
->collapse()
->all();
if (!$this->asyncMethod || ($this->asyncMethod && $this->async)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it's a good idea. But let's put it in a separate method:

protected function reparation(): array
{
    if (...) {
        return [];
    }

    return collect($this->layouts)->...;
}

What do you think about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you.

Yes, this is a good idea, thanks to this, the logic will be simplified and the code will become more readable.

I'm sorry, I use a modified version of the package at home, and sometimes I forget about the paths for the package
*/
protected function reparation(): array
{
if ($this->asyncMethod && !$this->async) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

During testing, I found that if we use asynchronous form loading and subsequently receive an error related to validation in it, it will not be displayed to us, since our asynchronous layout will not initially be loaded when the screen loads.

This error will be eliminated by adding an additional check.

if ($this->asyncMethod && !$this->async && !Session::get('errors')) {...

But in this case, again the null related error I mentioned earlier may occur.

For example, if you use something like:

$this->query->get('user')->exists

in our layout, since in case of receiving a validation error, we return to the past logic of behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants