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
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/Screen/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,24 @@ protected function buildAsDeep(Repository $repository)
{
$this->query = $repository;

if (! $this->isSee()) {
if (!$this->isSee()) {
return;
}

$build = collect($this->layouts)
->map(function ($layouts) {
return Arr::wrap($layouts);
})
->map(function (iterable $layouts, string $key) use ($repository) {
return $this->buildChild($layouts, $key, $repository);
})
->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.

$build = collect($this->layouts)
->map(function ($layouts) {
return Arr::wrap($layouts);
})
->map(function (array $layouts, string $key) use ($repository) {
return $this->buildChild($layouts, $key, $repository);
})
->collapse()
->all();
}

$variables = array_merge($this->variables, [
'manyForms' => $build,
'manyForms' => isset($build) ? $build : [],
'templateSlug' => $this->getSlug(),
'asyncEnable' => empty($this->asyncMethod) ? 0 : 1,
'asyncRoute' => $this->asyncRoute(),
Expand Down