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

90/edit preview mode support v3 review #4521

Merged

Conversation

mhsdesign
Copy link
Member

TASK: Remove half-baked solution of session independent preview's
Otherwise, this feature would only work for this one page, successive links will currently not have that query param added - the linking service still needs to learn this, but we delay this for another time.

TASK: RenderingModeService instances runtime cache

TASK: Introduce constant RenderingMode::FRONTEND for system integrated rendering mode

Otherwise, this feature would only work for this one page, successive links will currently not have that query param added - the linking service still needs to learn this, but we delay this for another time.
Copy link
Member

@mficzel mficzel left a comment

Choose a reason for hiding this comment

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

Like this in general. But the runtime cache implemented in the return statement is a bit too much flexing ;-)

My brain likes simple code and runtime caches that use early returns.

}
throw new Exception(
'The requested interface render mode "' . $modeName . '" is not configured.'
return $this->instances[$modeName] ??= match (true) {
Copy link
Member

Choose a reason for hiding this comment

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

I kinda dislike that you put the runtime cache in instances into one live with code that populates this.

Needlessly harder to read and unterstand. Offcourse the runtime cache makes sense.

Copy link
Member

@mficzel mficzel Sep 16, 2023

Choose a reason for hiding this comment

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

suggestion:

	public function findByName(string $modeName): RenderingMode
    {
        if ($instance = $this->instances[$modeName]) {
            return $instance;
        }
        if ($modeName === RenderingMode::FRONTEND) {
            $this->instances[$modeName] = RenderingMode::createFrontend();
        } else {
            $this->instances[$modeName] = RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName]);
        }
        return $this->instances[$modeName];        
    }

Copy link
Member

Choose a reason for hiding this comment

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

??= and match($modeName) would be fine for me. What is imho too much is the match true you have to use to thwrow the exception. Will adjust and the merge this into the other pr.

Funny is that even the php documentation does not explain that operator other than mentioning its existence.

Copy link
Member

@mficzel mficzel Sep 16, 2023

Choose a reason for hiding this comment

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

BTW: This would be fine for me ... but it will not throw on unconfigured modes

return $this->instances[$modeName] ??= match($modeName) {
   RenderingMode::FRONTEND => RenderingMode::createFrontend(),
   default => RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName])
};

@mhsdesign
Copy link
Member Author

mhsdesign commented Sep 16, 2023

Like this in general. But the runtime cache implemented in the return statement is a bit too much flexing ;-)

hehe i do understand what you mean. I was inspired by code I saw written from @grebaldi

phps newer match and ??= are indeed very powerful features that allow to write code much more compact. (On the cost of readability for people unfamiliar with this pattern)

i think at one point we might get used to such patterns more and that this is for now too early to use?

@mhsdesign
Copy link
Member Author

I won’t be on my pc today so please feel free to adjust the code as you liked (this was just a suggestion and it’s your pr after all ^^)

@mficzel mficzel force-pushed the 90/editPreviewModeSupport_v3_review branch from 9305987 to 5639b6b Compare September 16, 2023 14:43
@mficzel mficzel merged commit 3202c4e into 90/editPreviewModeSupport_v3 Sep 16, 2023
@mficzel mficzel deleted the 90/editPreviewModeSupport_v3_review branch September 16, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants